我正在尝试将django应用程序部署在Google云平台上。我正在使用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/
时,它将起作用并显示其中的文件夹。但是它不适用于静态中的任何子文件夹。它为静态里面的img文件夹提供了/usr/share/nginx/html/static/img/index.html
找不到。同样,当我尝试使用网址myIPaddress/
时,它会打开网站的主页,但同样,它对于其他任何链接均无效,并会显示错误消息。对于about页面,它给出错误/usr/share/nginx/html/about
失败(2:没有这样的文件或目录)。
答案 0 :(得分:1)
您关注的教程中有错误。 location = ...
完全匹配单个URI,而您需要匹配/static/
下面的所有URI。
使用:
location = /favicon.ico { ... }
location /static/ { ... }
location / { ... }
有关详细信息,请参见this document。