113 lines
3.5 KiB
Nginx Configuration File
113 lines
3.5 KiB
Nginx Configuration File
|
|
# Generated by nginxconfig.io
|
|||
|
|
# See nginxconfig.txt for the configuration share link
|
|||
|
|
|
|||
|
|
user nginx;
|
|||
|
|
pid /var/run/nginx.pid;
|
|||
|
|
worker_processes auto;
|
|||
|
|
worker_rlimit_nofile 65535;
|
|||
|
|
|
|||
|
|
# Load modules
|
|||
|
|
include /etc/nginx/modules-enabled/*.conf;
|
|||
|
|
|
|||
|
|
events {
|
|||
|
|
multi_accept on;
|
|||
|
|
worker_connections 65535;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
http {
|
|||
|
|
charset utf-8;
|
|||
|
|
sendfile on;
|
|||
|
|
tcp_nopush on;
|
|||
|
|
tcp_nodelay on;
|
|||
|
|
server_tokens off;
|
|||
|
|
log_not_found off;
|
|||
|
|
types_hash_max_size 2048;
|
|||
|
|
types_hash_bucket_size 64;
|
|||
|
|
client_max_body_size 16M;
|
|||
|
|
|
|||
|
|
# MIME
|
|||
|
|
include mime.types;
|
|||
|
|
default_type application/octet-stream;
|
|||
|
|
|
|||
|
|
# Logging
|
|||
|
|
access_log /dev/stdout;
|
|||
|
|
error_log /dev/stderr warn;
|
|||
|
|
|
|||
|
|
# 上游 Next.js 服务器(端口 3003)
|
|||
|
|
upstream nextjs {
|
|||
|
|
# 使用容器名称(如果在同一个 Docker 网络)
|
|||
|
|
server website-01:3002;
|
|||
|
|
# 如果使用宿主机 IP,取消下面这行注释,并注释上面那行
|
|||
|
|
# server 172.17.0.1:3002;
|
|||
|
|
keepalive 64;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# HTTP 服务器
|
|||
|
|
server {
|
|||
|
|
listen 8085;
|
|||
|
|
listen [::]:8085;
|
|||
|
|
server_name _;
|
|||
|
|
|
|||
|
|
# 静态资源缓存(由 Next.js 提供)
|
|||
|
|
location /_next/static {
|
|||
|
|
proxy_pass http://nextjs;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Connection "";
|
|||
|
|
expires 365d;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
location /static {
|
|||
|
|
proxy_pass http://nextjs;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
proxy_set_header Connection "";
|
|||
|
|
expires 365d;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 图标文件缓存
|
|||
|
|
location ~* \.(ico|svg|png|jpg|jpeg|gif|webp)$ {
|
|||
|
|
proxy_pass http://nextjs;
|
|||
|
|
expires 30d;
|
|||
|
|
add_header Cache-Control "public, immutable";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# API 路由代理
|
|||
|
|
location /api {
|
|||
|
|
proxy_pass http://nextjs;
|
|||
|
|
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 60s;
|
|||
|
|
proxy_send_timeout 60s;
|
|||
|
|
proxy_read_timeout 60s;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 所有其他请求代理到 Next.js(SSR)
|
|||
|
|
location / {
|
|||
|
|
proxy_pass http://nextjs;
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# gzip
|
|||
|
|
gzip on;
|
|||
|
|
gzip_vary on;
|
|||
|
|
gzip_proxied any;
|
|||
|
|
gzip_comp_level 6;
|
|||
|
|
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
|||
|
|
}
|
|||
|
|
}
|