Emtpy pages are delivered for PHP scripts
Closed this issue · 6 comments
Thank you for this project.
I'm trying to install a local wordpress test-site within a container based on your images but even a single php-site won't render correctly (it is empty). Here's what I did:
1- I created docker-compose.yml
adapted the code from your README accordingly (activated phpmyadmin and ssh) and ran docker-compose up -d
.
2- I can correctly retrieve the default index.html via my web-browser navigating to localhost:2080 (which is the port I chose for nginx:80)
3- I ssh into my instance
4- I create a index.php
with <?php phpinfo() ?>
in /data/nginx/www/index.php
5- I change /data/nginx/config/conf.d/default.conf
to
server {
[..]
location / {
root /data/nginx/www;
index index.php index.html index.htm; # added index.php
}
[..]
# pass the PHP scripts to FastCGI server listening on php:9000
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
include fastcgi_params;
}
[..]
Here I basically changed the fastcgi_param SCRIPT_FILENAME
to $fastcgi_script_name
.
6- Navigating to localhost:2080/index.php gives me a blank page - immediately (HTTP response is 200).
NGinx's error log does not contain an error.
What can I do to debug this issue?
PS: I tried setting fastcgi_param SCRIPT_FILENAME
to $document_root$fastcgi_script_name
, this results in the famous "Primary script unknown"-error.
I have fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
in configs in many websites and it works fine.
Did you restart nginx to apply config changes with docker-compose restart nginx
?
BTW, root
should already be set properly out of the box at server
level, so you don't need to duplicate it in location /
I restarted nginx, changes are taken into account (I see a difference between $document_root$fastcgi_script_name
and $fastcgi_script_name
alone).
These are the default config-files I pasted here. default.conf
and all of it is in the server-section.
Here's my complete default.conf (this only file I changed compared to the basic installation):
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /data/nginx/log/host.access.log main;
location / {
root /data/nginx/www;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /data/nginx/www;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on php:9000
#
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
This doesn't work. I get the File Not Found-error. However! When I add root /data/nginx/www;
inside the location ~ \.php$
section, then it works.
You either need to keep root
option in location ~ \.php$
with correct path (the same as in location /
) or set root
at server
level.
Nginx default config seems to be changed since last time I've made any major updates to these images. I've just pushed an update that changes default config and makes it more suitable out of the box.
Cool. Thanks.