【问题标题】:Why the url read as file or directory by the nginx server?为什么 nginx 服务器将 url 读取为文件或目录?
【发布时间】:2017-12-25 13:30:28
【问题描述】:
2017/07/20 06:05:34 [错误] 19472#0: *25 open() "/home/websites/gamoto.net/test/categoria/secondi-di-carne" 失败(2:否此类文件或目录),客户端:175.158.201.6,服务器:test.gamoto.net,请求:“GET /categoria/secondi-di-carne HTTP/1.1”,主机:“test.gamoto.net”,引用者:“ http://test.gamoto.net/"
这里有错误日志。
【问题讨论】:
标签:
nginx
webserver
nginx-location
【解决方案1】:
server {
listen 80;
server_name w4.gamoto.net;
root "R:/gamoto.net/test_html/";
index index.php;
#autoindex off;
location / {
rewrite ^/chi-siamo/?([a-z-]*)?/?$ /chi-siamo.php?chi=$1 last;
rewrite ^/categoria/?([a-z-]*)?/?([a-z0-9-]*)?/?$ /categoria.php?cat=$1&id=$2 last;
rewrite ^/nazione/italia/?([0-9]*)?/?$ /nazione.php?nazione=italia&pg=$1 last;
rewrite ^/nazione/italia/?([a-z0-9-]*)?/?([a-z0-9-]*)?/?$ /nazione.php?nazione=italia®ione=$1&id=$2 last;
rewrite ^/nazione/?([a-z-]*)?/?([0-9-]*)?/?$ /nazione.php?nazione=$1&id=$2 last;
rewrite ^/ricerca/?([a-z0-9-]*)?/?([0-9]*)?/?$ /ricerca.php?search=$1&pg=$2 last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass php_upstream;
#fastcgi_pass unix:var/run/php/php7.0-fpm.sock;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\.ht {
deny all;
}
}