server {
|
listen 8081;
|
server_name localhost; # 部署时替换成主机ip或域名
|
client_max_body_size 100M;
|
|
# 开启gzip
|
gzip on;
|
# https://blog.csdn.net/fxss5201/article/details/106535475
|
gzip_static on;
|
gzip_proxied any;
|
# 低于1kb的资源不压缩
|
gzip_min_length 1k;
|
gzip_buffers 4 16k;
|
gzip_comp_level 2;
|
# 需要压缩的类型
|
gzip_types text/plain application/javascript text/css application/xml text/javascript application/json;
|
# 是否添加“Vary: Accept-Encoding”响应头
|
gzip_vary on;
|
|
location /django_static/ {
|
alias /www/LunarLink/static/;
|
}
|
|
location /api/ {
|
proxy_pass http://lunar-link-django:8000/api/;
|
proxy_set_header Host $host;
|
proxy_set_header Cookie $http_cookie;
|
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_redirect default;
|
add_header Access-Control-Allow-Origin *;
|
add_header Access-Control-Allow-Headers X-Requested-With;
|
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
|
}
|
|
location /admin/ {
|
proxy_pass http://lunar-link-django:8000/admin/;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header Host $host;
|
proxy_redirect off;
|
}
|
|
location = / {
|
rewrite ^ /lunarlink/login redirect;
|
}
|
|
location / {
|
root /usr/share/nginx/html;
|
index index.html index.htm;
|
try_files $uri $uri/ /index.html;
|
}
|
}
|