After a very long chat with R0MANARMY and a lot of his help, I think I finally understood the root of the problem.
The main issue here is the fact that I was not using docker as it was intended to work.
Another cause is the fact that fpm is not a webserver, and the only way to proxy into it is through fastcgi (or maybe not the only, but simple proxy_pass does not work in this case).
So, the correct way of setting it up is:
- mounting the code volume into both containers.
- configure
fastcgi
for php scripts through nginx into php container
- configure virtual host to serve static assets directly by nginx.
Here are couple of examples of how to do it:
http://geekyplatypus.com/dockerise-your-php-application-with-nginx-and-php7-fpm/
https://ejosh.co/de/2015/08/wordpress-and-docker-the-correct-way/
UPDATE
Adding the actual solution that worked for me:
For faster turnaround, I decided to user docker-compose and docker-compose.yml looks like this:
website:
build: ./website/
container_name: website
external_links:
- mysql:mysql
volumes:
- ~/Dev/priz/website:/var/www/html
environment:
WORDPRESS_DB_USER: **
WORDPRESS_DB_PASSWORD: ***
WORDPRESS_DB_NAME: ***
WORDPRESS_DB_HOST: ***
proxy:
image: nginx
container_name: proxy
links:
- website:website
ports:
- "9080:80"
volumes:
- ~/Dev/priz/website:/var/www/html
- ./deployment/proxy/conf.d/default.conf:/etc/nginx/conf.d/default.conf
Now, the most important piece of information here is the fact that I am mounting exactly the same code to both containers. The reason for that, is because fastcgi cannot serve static files (at least as far as I understand), so the idea is to serve then directly through nginx.
My default.conf
file looks like this:
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /nginx_status {
stub_status on;
access_log off;
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass website:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_intercept_errors on;
include fastcgi_params;
}
}
So, this config, proxies through php request to be handled by fpm container, while everything else is taken from locally mounted volume.
That's it. I hope it will help someone.
The only couple of issues with it:
- ONLY sometimes
http://localhost:9080
downloads index.php file instead of executing it
- cURL'ing from php script to outside world, takes really long time not sure how to even debug this, at this point.