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 }

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

这样:

location  /a/b/c {
        proxy_pass http://127.0.0.1:10000/a/b/c;
}

似乎 location 后面不要等号
这是我一个django服务器的uwsgi配置

[uwsgi]
#使用nginx连接时使用,Django程序所在服务器地址
socket=127.0.0.1:8001
#直接做web服务器使用,Django程序所在服务器地址
#http=127.0.0.1:8000
#项目目录  (后端项目目录)
chdir=/home/ubuntu/website4
#项目中wsgi.py文件的目录,相对于项目目录
wsgi-file=website4/wsgi.py
# 进程数
processes=4
# 线程数
threads=2
# uwsgi服务器的角色
master=True
# 存放进程编号的文件
pidfile=uwsgi.pid
# 日志文件,因为uwsgi可以脱离终端在后台运行,日志看不见。我们以前的runserver是依赖终端的
daemonize=uwsgi.log
virtualenv=/home/ubuntu/anaconda3/envs/website4

然后我的nginx

user root;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {
    upstream website4 {
        server 127.0.0.1:8001;
    }
      # 电脑版网页 + api
    server {
        listen      80;
        server_name *******;
        charset     utf-8;
        location /api/v1/ {
            include uwsgi_params;
            uwsgi_pass website4;
        }
        location /media {
            alias /home/ubuntu/website4/media;
        }
        location  / {
            root /home/ubuntu/appfront; # 前端界面目录
            index index.html;
            try_files $uri $uri/ /index.html; # 如果页面的文件里只有一个 index.html 一定要加这个,不然访问非 index 的页面会404
        }
    }
      # 手机版网页
    server {
        listen      80;
        server_name ***;
        charset     utf-8;
        location / {
            root /home/ubuntu/websiteapp;
            index index.html;
            try_files $uri $uri/ /index.html;
        }
    }
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    gzip on;
    include /etc/nginx/conf.d/*.conf;
}

如果前端是用django的话部署前要先导出静态文件用nginx分发
我这边是按前后端分离的配置(drf + vue)