0
I am trying to have nginx on container 1 connect to the php-fpm running wordpress on container 2 on port 9000. It seems to work for dynamically generated content, such a post, but static content such as CSS, JS or images return a 404. What might be causing this?
Please note that the first "server" block is intended to catch all non-HTTP requests and redirect them to HTTPS, while the second is intended to be "catch all" for those sent "mysite.com".
Thank you,
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
listen [::]:80;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name localhost;
ssl_certificate /etc/ssl/cert.pem;
ssl_certificate_key /etc/ssl/privkey.pem;
ssl_session_cache shared:SSL:1m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/local/www/nginx;
index index.html index.htm;
}
}
server {
server_name mysite.com
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/ssl/cert.pem;
ssl_certificate_key /etc/ssl/privkey.pem;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
set $my_https $https;
if ($http_x_forwarded_proto = 'https') {
set $my_https 'on';
}
root /var/wordpress;
fastcgi_pass 192.168.10.6:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/wordpress$fastcgi_script_name;
include fastcgi_params;
}
}
}
You haven't set a
root
statement. What path should container 1 use to access the static files? – Richard Smith – 2019-06-27T07:14:12.827I added the
root
statement. The pathvar/wordpress
is the root directory of wordpress on the wordpress container, as reflected above. There was no change in the behavior. – Farhan Yusufzai – 2019-06-27T23:02:42.083You seem to have added
root
to the wrongserver
block. But it's still not clear if your Nginx instance can see the WordPress static content. WordPress is a PHP application that requires a webserver to serve the static content. Normally, WordPress in a VM/jail/container/whatever would need, for example, Nginx & php-fpm to serve static/dynamic content. – Richard Smith – 2019-06-28T07:26:43.083I see, I might have had a misunderstanding here. My current system is: Nginx on container 1 (public facing) -> Nginx on container 2 -> php-fpm also on container 2. I was hoping to get rid of the middle nginx layer, but perhaps that is not possible? – Farhan Yusufzai – 2019-06-30T00:35:12.960