Я прикрепил свой файл конфигурации Nginx для своего сайта по умолчанию, который работает в Ubuntu.
Я пытаюсь достичь следующего:
/usr/share/nginx/www
с файлом по умолчанию index.php
403.html
который сидит в /usr/share/nginx/www
основной каталогНо что происходит, когда я захожу на сайт с другого IP-адреса (тот, которому отказано в доступе), он загружает страницу 403.html, но загружает файл под названием «загрузка». Если я перейду на example.com/index.php, он загрузит файл index.php.
Что-то настроено неправильно, но не знаете, что это такое.
server {
listen 80;
root /usr/share/nginx/www;
index index.php;
server_name example.com;
location / {
try_files $uri $uri/ /index.php;
# restrict IP's
allow 123.456.789.0;
allow 123.456.789.1;
deny all;
}
location = /403.html {
root /usr/share/nginx/www;
allow all;
}
error_page 404 /404.html;
error_page 403 /403.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
# root /var/www;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Вам следует переместить свои правила отказа из location /
на один уровень выше, потому что теперь они не применяются к запросам php.
server {
listen 80;
root /usr/share/nginx/www;
index index.php;
server_name example.com;
allow 123.456.789.0;
allow 123.456.789.1;
deny all;
location / {
try_files $uri $uri/ /index.php;
}
#....
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}