Nginx 可以访问静态文件夹,但不能访问其中的其他文件夹。抛出 sub-folder/index.html 未找到
Nginx can access static folder but not other folders inside it. Throws sub-folder/index.html is not found
我正在尝试在 google 云平台上部署我的 Django 应用程序。我正在使用 nginx 和 gunicorn。我正在关注 this guide。
我在 sites-available 文件夹下创建了一个文件 - le_website
。这是代码 -
server {
listen 80;
server_name 10.xxx.x.x;
location = /favicon.ico {access_log off;log_not_found off;}
location = /static/ {
root /home/jainpriyanshu1991/learnEarn/le-webiste;
}
location = / {
include proxy_params;
proxy_pass http://unix:/home/jainpriyanshu1991/learnEarn/le-webiste/le_website.sock;
}
}
当我尝试 url myIPaddress/static/
时,它起作用并显示其中的文件夹。但它不适用于静态中的任何子文件夹。它给出 /usr/share/nginx/html/static/img/index.html
is not found for img folder inside static。同样,当我尝试 url myIPaddress/
时,它会打开网站的主页,但同样,它对任何其他 link 都不起作用并给出错误。对于关于页面,它给出错误 /usr/share/nginx/html/about
failed (2: No such file or directory).
您所遵循的教程中存在错误。 location = ...
完全匹配单个 URI,而您需要匹配 /static/
.
以下的所有 URI
使用:
location = /favicon.ico { ... }
location /static/ { ... }
location / { ... }
详情见this document。
我正在尝试在 google 云平台上部署我的 Django 应用程序。我正在使用 nginx 和 gunicorn。我正在关注 this guide。
我在 sites-available 文件夹下创建了一个文件 - le_website
。这是代码 -
server {
listen 80;
server_name 10.xxx.x.x;
location = /favicon.ico {access_log off;log_not_found off;}
location = /static/ {
root /home/jainpriyanshu1991/learnEarn/le-webiste;
}
location = / {
include proxy_params;
proxy_pass http://unix:/home/jainpriyanshu1991/learnEarn/le-webiste/le_website.sock;
}
}
当我尝试 url myIPaddress/static/
时,它起作用并显示其中的文件夹。但它不适用于静态中的任何子文件夹。它给出 /usr/share/nginx/html/static/img/index.html
is not found for img folder inside static。同样,当我尝试 url myIPaddress/
时,它会打开网站的主页,但同样,它对任何其他 link 都不起作用并给出错误。对于关于页面,它给出错误 /usr/share/nginx/html/about
failed (2: No such file or directory).
您所遵循的教程中存在错误。 location = ...
完全匹配单个 URI,而您需要匹配 /static/
.
使用:
location = /favicon.ico { ... }
location /static/ { ... }
location / { ... }
详情见this document。