【发布时间】:2020-06-12 12:26:33
【问题描述】:
我正在尝试使用 nginx 设置测试服务器块。我尝试了很多方法,但 test.myserver.com 总是向我显示 404。我的目标是在 /var/www/test/html/index.html 中显示 index.html。
这是我目前所拥有的:
server {
listen 80;
listen [::]:80;
# SSL configuration
#
listen 443 ssl;
listen [::]:443 ssl;
root /var/www/test;
index index.html index.htm index.nginx-debian.html;
server_name test.myserver.com www.test.myserver.com;
location ^~ /html {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files index.html $uri $uri/ / =404;
}
location / {
index /html/index.html;
}
如您所见,我已经在尝试不同的方式。我从here 获得了 ^~ 文件夹位置的想法。
那么:为什么 nginx 会给我 404,我该如何解决?
【问题讨论】:
-
为什么不设置
root /var/www/test/html;,因为那似乎是正确的文档根目录?
标签: nginx http-status-code-404