my nginx config for domain looks like below:
server {
listen *:80;
server_name mywebsite.org ;
root /var/www/mywebsite.org/web;
index index.html index.htm index.php index.cgi index.pl index.xhtml;
error_page 400 /error/400.html;
error_page 401 /error/401.html;
error_page 403 /error/403.html;
error_page 404 /error/404.html;
error_page 405 /error/405.html;
error_page 500 /error/500.html;
error_page 502 /error/502.html;
error_page 503 /error/503.html;
recursive_error_pages on;
location = /error/400.html {
internal;
}
location = /error/401.html {
internal;
}
location = /error/403.html {
internal;
}
location = /error/404.html {
internal;
}
location = /error/405.html {
internal;
}
location = /error/500.html {
internal;
}
location = /error/502.html {
internal;
}
location = /error/503.html {
internal;
}
error_log /var/log/ispconfig/httpd/mywebsite.org/error.log;
access_log /var/log/ispconfig/httpd/mywebsite.org/access.log combined;
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /stats/ {
index index.html index.php;
auth_basic "Members Only";
auth_basic_user_file /var/www/clients/client0/web15/web/stats/.htpasswd_stats;
}
location ^~ /awstats-icon {
alias /usr/share/awstats/icon;
}
location ~ \.php$ {
try_files /b55a31c419b809eb02d1c0a0c8f6e014.htm @php;
}
location @php {
# try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/web15.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
location / {
root /var/www/mywebsite.org/web/mainpage;
try_files $uri $uri/ /index.php?$args;
}
}
This configuration is default config with use ISPConfig panel, I've just added "location /" directives becouse my website is in folder /mainpage.
My problem: if index.php is in folder /mainpage then nginx doesn't read it and read index.php one folder upper "/web" BUT if I put in folder /mainpage file index.html then server read it correct… For me this behave it's weird. Why server read correct file index.html in /mainpage but in the same folder index.php no. After delete/rename file index.html in folder /mainpage the server automatically read file index.php one folder upper "/web". Dont want read index.php in /mainpage folder.
Best Answer
index.html
matcheslocation /
only butindex.php
matcheslocation ~ \.php$
and then it is handled bylocation @php
. See Documentation for nginxlocation
directive matching order.You can try fixing you problem by replacing
$document_root
inlocation @php
with/var/www/mywebsite.org/web/mainpage