关于最近版本打包生成的静态文件 Nginx 配置问题 #240
-
请教大佬,打包后生成的 client 和 server 如何在 Nginx 配置 |
Beta Was this translation helpful? Give feedback.
Answered by
surmon-china
Nov 28, 2023
Replies: 2 comments
-
Line 30 in c1db305 BFF Server 的逻辑中包含基于 Node.js 启动的 static 静态资源服务,所以理论上 Nginx 仅需启动一个 server 指向对应端口的 proxy 就可以了。但如果你希望静态服务效率更高的话,可以在 Nginx 中直接拦截静态文件的后缀而直接指向应用的静态目录。 类似这样: server {
listen 80;
listen [::]:80;
listen 443 ssl http2 fastopen=3 reuseport;
listen [::]:443 ssl http2 fastopen=3 reuseport;
server_name domain.com www.domain.me;
resolver_timeout 10s;
resolver 8.8.8.8 valid=300s;
ssl_certificate /var/xxx/ssl.cert.pem;
ssl_certificate_key /var/xxx/ssl.cert.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 60m;
ssl_session_tickets on;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=31536000";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection 1;
# Bff Server
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Country-Code $geoip2_data_country_code;
proxy_set_header Country-Name $geoip2_data_country_name;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
}
# Static
location ~* ^.+\.(avif|webp|jpg|jpeg|gif|png|ico|otf|ttf|js|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|flv|swf|html|htm)$ {
log_not_found off;
access_log off;
etag on;
expires max;
autoindex off;
root /var/wwwroot/surmon.me/root/dist/client/;
}
access_log /var/wwwlogs/nginx/xxx.access.log main;
error_log /var/wwwlogs/nginx/xxx-error.log;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
leehave
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
surmon.me/src/server/index.ts
Line 30 in c1db305
BFF Server 的逻辑中包含基于 Node.js 启动的 static 静态资源服务,所以理论上 Nginx 仅需启动一个 server 指向对应端口的 proxy 就可以了。但如果你希望静态服务效率更高的话,可以在 Nginx 中直接拦截静态文件的后缀而直接指向应用的静态目录。
类似这样: