Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP downloads for Static #330

Open
Mr-Wulf opened this issue Dec 1, 2022 · 4 comments
Open

PHP downloads for Static #330

Mr-Wulf opened this issue Dec 1, 2022 · 4 comments

Comments

@Mr-Wulf
Copy link

Mr-Wulf commented Dec 1, 2022

Edit: "Solution" in the post below.
Note: It works, its ugly and not artful at all, I would LOVE if someone who has NGINX expertise above mine (i.e. Banging the files together until sparks fly) could fix this the proper way.

First let me say how happy I have been with SteveLTN/https-portal docker deployment.
Such a time saver for such a newb as me.

I have set up a couple websites (One WordPress and One Static). Everything works, including certs.
PROBLEM:
When I access https://stat.mysite.com/index.php - The file downloads rather than executes.
This is on the static website.
The Wordpress (Which uses PHP) operates ok.

I have done some research and it appears that there are some configurations necessary in "/etc/nginx/sites-available/mydomain.com.conf" AFAIK?

Q1: What is the best way to affect those configuration changes (so I can execute https://stat.mysite.com/index.php rather than download it)

Q2: If I use the changes to "/etc/nginx/sites-available/mydomain.com.conf" approach, can I selectively replace only the section that deals with .php? To be honest. I could not replace the entire .conf as I have no idea how to drive NGINX (I only used apache and that was in a very basic way).

AFAIK: This is the section in .conf that makes the .php execute

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

The relevant parts of my docker-compose.yml are as follows;

version: "3.7"

services:

   nginx:
     image: steveltn/https-portal:1
     container_name: nginx-proxy
     depends_on:
       - wp1
     restart: always
     ports:
       - "443:443"
       - "80:80"
     environment:
       CLIENT_MAX_BODY_SIZE: 100M
       DOMAINS: 'stat.mysite.com,
www.mysite.com -> http://wp1:80,
dat.mysite.com -> http://adminer1:8080,
mysite.com => www.mysite.com'

       STAGE: production
     volumes:
        # We only need this one for max file size change for uploads
#       - /usr/srv/nginx.conf:/etc/nginx/conf.d/default.conf
       - /usr/srv/vol_logs_nginx:/var/log/nginx
        # Static site directory
       - /usr/srv/vol_html:/var/www/vhosts
#       - /usr/srv/client_max_body_size.conf:/etc/nginx/conf.d/client_max_body_size.conf

...

#############
volumes:
      vol_logs_nginx:
      vol_ssl_certs:
      vol_proc:

# Deez r for DB
      data_mysql1:
      data_wordpress1:
# Static html
      vol_html:

networks:
  default:
    #    external:
    name: nginx-proxy-net

I would appreciate some insight into this. This is for a community website.

@Mr-Wulf
Copy link
Author

Mr-Wulf commented Dec 2, 2022

Ok... Seemingly making progress. Found this resource, how to set up a PHP container with NGINX docker.
It does seem to have the right methodology. My problem appears to be integrating this approach into the .YML I already organically developed as working.

https://blog.devsense.com/2019/php-nginx-docker

I tried it and it basically destroyed the entire setup I had working.
I think its because of the DOCKERFILE changes in the article.
Luckily I had a .YML backup and rolling it back restored ops.

So the questions I have now is:

Q1. How to reconcile the DOCKERFILE provided with SteveLNT/https-portal with the changes to "default.conf" in the article.
As in... Do I use the DOCKERFILE for https-portal on Github and then kludge the changes from the article?

Q2. In my docker cofig (that worked) I had DOMAINS: 'stat.mysite.com,
But now, it seems that there is a separate config to the static directory.
Would I be able to use DOMAINS: stat.mysite.com -> http://php:80,
or do I have to use some frankenstein cludge?

I am sorry that these questions are so basic. But it would really help others (of my low skill level) implementing SteveLTN/https-portal for PHP enabled 'static' websites.

@Mr-Wulf
Copy link
Author

Mr-Wulf commented Dec 4, 2022

Update:

Ok... what do you know... Reading Documentation might have the answer!
I think that THIS bit in the doc might be my saviour!

Stay tuned. Would be nice to solve my own 'query' that migh help future people :-)

@trailrunn3r
Copy link

@Mr-Wulf i would be interested in your solution, looks like i'll be facing a similar issue...

@Mr-Wulf
Copy link
Author

Mr-Wulf commented Dec 7, 2022

The "SOLUTION"

I am sorry, do not beat me with sticks, I know NOTHING.

...but it works.

Ok...Here is how to 'fix' this... Install a WORD PRESS instance without the database... or without any of the files for that matter. WP/SteveLTN/NGINX has magic that makes PHP execute in WP containers. If anyone could just extract that gem, that would be nice.

Relevant bits of the docker-compose.yml

version: "3.7"

services:

   nginx:
     image: steveltn/https-portal:1
     container_name: nginx-proxy
     depends_on:
       - wp1
     restart: always
     ports:
       - "443:443"
       - "80:80"
     environment:
       CLIENT_MAX_BODY_SIZE: 100M
       DOMAINS: 'stat.mysite.com -> http://wp0:80,
www.mysite.com -> http://wp1:80,
dat.mysite.com -> http://adminer1:8080,
mysite.com => www.mysite.com'

Note: The only change is that the 'static' site is now pointing into another Wordpress container (WP0)
I have tried having it point to a PHP only container but (not surprisingly?) it did nothing.

   wp0:
     container_name: wp0
     image: wordpress:6.0.1
     restart: always

     volumes:
       - "/usr/srv/data_wordpress0:/var/www/html"
       - "/tmp/wp_site0:/usr/srv/wp_site0_tmp"

Note: There is no database link, no environmentals for this WP instance, indeed NOTHING but the image that it draws down.
The first volume, is now your new 'static' root.

Step 1.
You run it once - to download the WP instance.

Step 2.
Run it to test. Accessing the 'static' website will now display the WP config screen. This is to test it only, as we are not doing any configuration.

Step 3.
Delete EVERYTHING. We actually don't need any of the WP file. NONE. We really only want the NGINX config that makes this possible.

The only file you care about is your index.php file. Now you can play with HTML/PHP as you otherwise would.

Please forgive me, this hack is born out of my ignorance of pretty much all the systems involved in this... but it works.

If someone has a more elegant way to do this. Please advise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants