根目录在nginx中显示404
Root directory shows 404 in nginx
我是 nginx 服务器的新手。我试图设置一个新的 url "/images/" 来提供图片。我编辑了启用站点的文件夹中的 bi.site 文件。
server {
listen *:80;
access_log /var/log/myproject/access_log;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /images/ {
root /www/myproject/files_storage;
}
}
然后在 /www/myproject/files_storage 位置我放了一个 temp.txt 文件。
当我输入 http://www.main_url/images/temp.txt
时,它显示 404 未找到。我究竟做错了什么 ?我错过了什么重要的东西吗?
这个:
location /images/ {
root /www/myproject/files_storage;
}
结果在/www/myproject/files_storage/images路径,如果你设置error_log就很明显了。所以使用 "alias" 指令而不是 "root"
http://nginx.org/en/docs/http/ngx_http_core_module.html#alias
我是 nginx 服务器的新手。我试图设置一个新的 url "/images/" 来提供图片。我编辑了启用站点的文件夹中的 bi.site 文件。
server {
listen *:80;
access_log /var/log/myproject/access_log;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /images/ {
root /www/myproject/files_storage;
}
}
然后在 /www/myproject/files_storage 位置我放了一个 temp.txt 文件。
当我输入 http://www.main_url/images/temp.txt
时,它显示 404 未找到。我究竟做错了什么 ?我错过了什么重要的东西吗?
这个:
location /images/ {
root /www/myproject/files_storage;
}
结果在/www/myproject/files_storage/images路径,如果你设置error_log就很明显了。所以使用 "alias" 指令而不是 "root"
http://nginx.org/en/docs/http/ngx_http_core_module.html#alias