【发布时间】:2019-10-04 18:01:01
【问题描述】:
我是 nginx 服务器的新手。我陷入了 URL 重定向。我在默认文件中有以下几行。
server {
listen 80;
root /home/ubuntu/web/server/current/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
error_log /home/ubuntu/web/error.log info;
location / {
# try_files $uri $uri/ /index.php?$query_string;
# try_files $uri $uri/ =404;
}
rewrite ^/web/(.*) /web/;
location /web/ {
alias /home/ubuntu/web/client/web/;
# try_files $uri $uri/ index.html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
我对上述重写规则的期望是 - 所有像 - http://example.com/web/login、http://exmpale.com/web/dashboard 这样的 URL 都将被重定向到 /home/ubuntu/web/client/web/ 并且要访问的默认页面是 index.html 文件。
当我打开错误日志文件时,我发现了类似的错误 -
重写或内部重定向循环,同时内部重定向到“/web/index.php”,客户端:ip_address,服务器:_,请求:“GET /web/ HTTP/1.1”,主机:“ipaddress”
我在这里做错了什么。
【问题讨论】:
-
显然默认页面是
index.php而不是index.html,因为这是您的index语句的顺序。但是您的rewrite语句导致了循环。您可以尝试重写为/web/index.html以绕过index顺序和循环。 -
@RichardSmith 我试过
index index.html index.htm index.php。不幸的是没有工作。谢谢回复,您还有什么疑问。
标签: nginx url-rewriting