121 lines
3.5 KiB
Nginx Configuration File
121 lines
3.5 KiB
Nginx Configuration File
|
|
# 活牛采购系统Nginx配置文件
|
|||
|
|
# 此配置文件用于配置Nginx作为反向代理服务器,提供HTTPS访问
|
|||
|
|
|
|||
|
|
user nginx;
|
|||
|
|
worker_processes auto;
|
|||
|
|
error_log /var/log/nginx/error.log;
|
|||
|
|
pid /run/nginx.pid;
|
|||
|
|
|
|||
|
|
# 加载动态模块
|
|||
|
|
include /usr/share/nginx/modules/*.conf;
|
|||
|
|
|
|||
|
|
events {
|
|||
|
|
worker_connections 1024;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
http {
|
|||
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|||
|
|
'$status $body_bytes_sent "$http_referer" '
|
|||
|
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
|||
|
|
|
|||
|
|
access_log /var/log/nginx/access.log main;
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
# 开启gzip压缩
|
|||
|
|
gzip on;
|
|||
|
|
gzip_disable "msie6";
|
|||
|
|
gzip_vary on;
|
|||
|
|
gzip_proxied any;
|
|||
|
|
gzip_comp_level 6;
|
|||
|
|
gzip_buffers 16 8k;
|
|||
|
|
gzip_http_version 1.1;
|
|||
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
|||
|
|
|
|||
|
|
# 虚拟主机配置 - 活牛采购系统后端API
|
|||
|
|
server {
|
|||
|
|
# 监听HTTP端口,重定向到HTTPS
|
|||
|
|
listen 80;
|
|||
|
|
server_name wapi.yunniushi.cn;
|
|||
|
|
return 301 https://$server_name$request_uri;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
server {
|
|||
|
|
# 监听HTTPS端口
|
|||
|
|
listen 443 ssl http2;
|
|||
|
|
server_name wapi.yunniushi.cn;
|
|||
|
|
|
|||
|
|
# SSL证书配置
|
|||
|
|
ssl_certificate /etc/nginx/ssl/wapi.yunniushi.cn/fullchain.pem;
|
|||
|
|
ssl_certificate_key /etc/nginx/ssl/wapi.yunniushi.cn/privkey.pem;
|
|||
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|||
|
|
ssl_prefer_server_ciphers off;
|
|||
|
|
ssl_session_timeout 1d;
|
|||
|
|
ssl_session_cache shared:SSL:10m;
|
|||
|
|
ssl_session_tickets off;
|
|||
|
|
|
|||
|
|
# HSTS配置
|
|||
|
|
add_header Strict-Transport-Security "max-age=63072000" always;
|
|||
|
|
|
|||
|
|
# 安全头部配置
|
|||
|
|
add_header X-Frame-Options DENY;
|
|||
|
|
add_header X-Content-Type-Options nosniff;
|
|||
|
|
add_header X-XSS-Protection "1; mode=block";
|
|||
|
|
|
|||
|
|
# 反向代理配置
|
|||
|
|
location / {
|
|||
|
|
# 代理到Node.js后端服务
|
|||
|
|
proxy_pass http://localhost:4330;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
proxy_set_header Connection 'upgrade';
|
|||
|
|
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_cache_bypass $http_upgrade;
|
|||
|
|
|
|||
|
|
# 增加代理超时
|
|||
|
|
proxy_connect_timeout 600s;
|
|||
|
|
proxy_send_timeout 600s;
|
|||
|
|
proxy_read_timeout 600s;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 静态文件服务配置(如果需要)
|
|||
|
|
# location /public {
|
|||
|
|
# alias /data/nodejs/yunniushi/public;
|
|||
|
|
# expires 30d;
|
|||
|
|
# }
|
|||
|
|
|
|||
|
|
# 健康检查端点
|
|||
|
|
location /health {
|
|||
|
|
proxy_pass http://localhost:4330;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
access_log off;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# API文档端点
|
|||
|
|
location /api/docs {
|
|||
|
|
proxy_pass http://localhost:4330;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 错误页面配置
|
|||
|
|
error_page 500 502 503 504 /50x.html;
|
|||
|
|
location = /50x.html {
|
|||
|
|
root /usr/share/nginx/html;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 加载其他配置文件
|
|||
|
|
include /etc/nginx/conf.d/*.conf;
|
|||
|
|
}
|