46 lines
1.2 KiB
Plaintext
46 lines
1.2 KiB
Plaintext
|
|
# Nginx 静态文件服务 + 智能代理
|
|||
|
|
|
|||
|
|
server {
|
|||
|
|
# 静态资源根目录
|
|||
|
|
root /usr/share/nginx/html;
|
|||
|
|
|
|||
|
|
# 前端资源路径别名(/sys/ -> /)
|
|||
|
|
location /sys/ {
|
|||
|
|
alias /usr/share/nginx/html/;
|
|||
|
|
try_files $uri $uri/ =404;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
index index.html;
|
|||
|
|
|
|||
|
|
# SSL 配置
|
|||
|
|
listen 443 ssl;
|
|||
|
|
ssl_certificate /etc/nginx/ssl/fullchain.pem;
|
|||
|
|
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
|
|||
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|||
|
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
|||
|
|
|
|||
|
|
# 1. 先尝试作为静态文件查找
|
|||
|
|
location / {
|
|||
|
|
try_files $uri $uri/ @proxy;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 2. 无法找到的请求(API路径)代理到后端
|
|||
|
|
location @proxy {
|
|||
|
|
# 判断URI最后一段是否有扩展名
|
|||
|
|
# 有扩展名返回404,无扩展名则代理
|
|||
|
|
if ($uri ~ \.[^./]+$) {
|
|||
|
|
return 404;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
proxy_pass http://116.204.74.41:8000;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|||
|
|
proxy_connect_timeout 30s;
|
|||
|
|
proxy_send_timeout 30s;
|
|||
|
|
proxy_read_timeout 30s;
|
|||
|
|
}
|
|||
|
|
}
|