Next.js
部署记录
/etc/nginx/sites-enabled/default
不同于 Vue 项目,由 Nginx 直接反向代理 index.html,Next.js 项目需额外配置。
nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
# 如果您有域名,请替换为您的域名
# server_name _;
# 设置为您的 Next.js 项目根目录
root /var/www/***;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /_next/static/ {
alias /var/www/***/.next/static/;
expires 365d;
access_log off;
}
location /public/ {
alias /var/www/***/public/;
expires 365d;
access_log off;
}
# 添加对 favicon.ico 和 robots.txt 的处理
# location = /favicon.ico { access_log off; log_not_found off; }
# location = /robots.txt { access_log off; log_not_found off; }
# 禁止访问 . 文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}另外,需要利用 pm2 启动 Next.js 项目
pm2 start pnpm --name "***" -- start
pm2 start pnpm --name "***" -- start:prod
npm config set registry https://mirrors.tencent.com/npm/
/home/ubuntu/***
React
NGINX配置
nginx
server {
listen 80;
server_name example.com;
root /path/to/your/vite/react/build;
index index.html;
# 启用gzip压缩
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.html;
}
# 静态资源缓存设置
location ~* \.(?:css|js|jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# 禁止访问 . 文件
location ~ /\. {
deny all;
}
}Nest.js
NGINX配置
nginx
server {
server_name your_domain www.your_domain;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}HTTPS NGINX配置
nginx
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name ***;
ssl_certificate /etc/nginx/secret/***_bundle.crt;
ssl_certificate_key /etc/nginx/secret/***.key;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
location / {
proxy_pass http://localhost:3000;
}
}gradle配置
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7897