events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 60s;
#server {
#listen 80 default_server;
#server_name _;
#return 404;
#}
# 后端 server
server {
listen 8000;
server_name dvadmin-django;
charset utf-8;
location / {
root html;
include /usr/local/nginx/conf/uwsgi_params;
uwsgi_pass 0.0.0.0:9000;
uwsgi_param UWSGI_SCRIPT application.wsgi;
uwsgi_param UWSGI_CHDIR /data/site/op/backend/; #项目路径
}
# Django media
location /media {
root /data/site/op/backend/media; # your Django project's media files - amend as required
}
# Django static
location /static {
root /data/site/op/backend/static; # your Django project's static files - amend as required
}
access_log /data/logs/backend.access.log;
error_log /data/logs/backend.error.log info;
}
# 前端配置
server {
listen 80;
server_name dvadmin-ui;
charset utf-8;
location / {
try_files $uri $uri/ @router; #需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
root /data/site/op/ui/dist/;
add_header Cache-Control max-age=no-cache;
index index.html index.php index.htm;
}
location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
access_log off;
add_header Cache-Control max-age=604800;
root /data/site/op/ui/dist/;
index index.html index.php index.htm;
}
location @router {
rewrite ^.*$ /index.html last;
}
access_log /data/logs/ui.access.log;
error_log /data/logs/ui.error.log;
}
}
VUE_APP_BASE_API = 'http://dvadmin-django:9000') uwsgi的9000端口
2022/05/04 15:37:35 [error] 19183#0: *8 upstream prematurely closed connection while reading response header from upstream, client: xx.xx.xx.xx, server: dvadmin-django, request: "GET /admin/captcha/refresh/ HTTP/1.1", upstream: "uwsgi://0.0.0.0:9000", host: "dvadmin-django:8000", referrer: "http://dvadmin-ui/"
2022/05/04 15:37:40 [info] 19183#0: *8 client xx.xx.xx.xx closed keepalive connection