abucike 2022-07-20 17:54 采纳率: 0%
浏览 44
已结题

centos+django+nginx+uwsgi部署路径问题?

诚心请教,看了好多帖子都没解决问题,实在麻烦了~

1、目前uwsgi配置,正常启动,还可以访问 http://49.234.32.152:8000/ ,页面和静态资源都ok。

  1 [uwsgi]
  2 http=0.0.0.0:8000
  3 #socket=0.0.0.0:8000
  4 chdir=/usr/local/project/myweb
  5 wsgi-file=myweb/wsgi.py
  6 process=4
  7 threads=2
  8 pidfile=uwsgi.pid
  9 daemonize=uwsgi.log
 10 master=Ture
 11 
 12 #static-map=/static=/usr/local/project/protest/static
 13 
 14 static-map=/static=static

2、Nginx启动
关闭上面uwgi的http,打开socket;
结果就只能访问首页,其他链接打开就404,静态的也不能访问
报错目录:[error] 10874#10874: *287 "/usr/share/nginx/html/admin/index.html"
怎么会变成这个目录,不应该是到项目目录吗?chdir=/usr/local/project/myweb

现在只需解决能打开正确目录,访问链接其他html,和静态文件就可以,不考虑nginx其他功能。

  1 user nginx;
  2 worker_processes auto;
  3 error_log /var/log/nginx/error.log;
  4 pid /run/nginx.pid;
  5 events {
  6     worker_connections 1024;
  7 }
  8 http {
  9     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 10                       '$status $body_bytes_sent "$http_referer" '
 11                       '"$http_user_agent" "$http_x_forwarded_for"';
 12     access_log  /var/log/nginx/access.log  main;
 13     sendfile            on;
 14     tcp_nopush          on;
 15     tcp_nodelay         on;
 16     keepalive_timeout   65;
 17     types_hash_max_size 4096;
 18     include             /etc/nginx/mime.types;
 19     default_type        application/octet-stream;
 20     server {
 21         listen       80;
 22         listen       [::]:80;
 23         server_name  _;
 24         include /etc/nginx/default.d/*.conf;
 25         location = / {      #  就只是修改了这里的配置
 26                 uwsgi_pass 0.0.0.0:8000;
 27                 include /etc/nginx/uwsgi_params;
 28         }
 29     }
 30 }
  • 写回答

2条回答 默认 最新

  • ilmss 2022-07-20 20:53
    关注
    获得1.50元问题酬金

    你要配下location, 我最近刚搞了下nginx,很简单, 你需要添加你的静态资源路径。

    这样:

    location  /a/b/c {
            proxy_pass http://127.0.0.1:10000/a/b/c;
    }
    
    
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 7月28日
  • 创建了问题 7月20日