worker_processes auto; # 自动根据CPU核心数设置 events { worker_connections 1024; multi_accept on; use epoll; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # 基础优化配置 sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; server_tokens off; # 隐藏版本号 # 性能优化配置 client_max_body_size 20m; client_body_buffer_size 128k; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; # 全局 gzip 配置 gzip on; gzip_vary on; gzip_min_length 10240; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript; gzip_disable "MSIE [1-6]\."; # 日志配置优化 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 buffer=512k flush=1m; error_log /var/log/nginx/error.log warn; # 允许跨域访问 map $http_origin $cors_origin { default ""; "~^https?://[^/]+\.hht\.test(:[0-9]+)?$" "$http_origin"; "~^https?://localhost(:[0-9]+)?$" "$http_origin"; } # 通用安全头部配置 map $http_upgrade $connection_upgrade { default upgrade; '' close; } # 通用配置块 include /etc/nginx/conf.d/*.conf; # 通用安全头部 add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "no-referrer-when-downgrade" always; add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always; # 错误页面配置 error_page 404 /404.html; error_page 500 502 503 504 /50x.html; # Element2 子域名配置 server { listen 80; server_name element2.hht.test; access_log /var/log/nginx/element2.access.log main; error_log /var/log/nginx/element2.error.log warn; location / { root /usr/share/nginx/html/element2; index index.html index.htm; try_files $uri $uri/ /index.html; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } } # Element3 子域名配置 server { listen 80; server_name element3.hht.test; access_log /var/log/nginx/element3.access.log main; error_log /var/log/nginx/element3.error.log warn; location / { root /usr/share/nginx/html/element-plus; index index.html index.htm; try_files $uri $uri/ /index.html; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } } # Vue2 子域名配置 server { listen 80; server_name vue2.hht.test; access_log /var/log/nginx/vue2.access.log main; error_log /var/log/nginx/vue2.error.log warn; location / { alias /usr/share/nginx/html/v2.cn.vuejs.org/; index index.html index.htm; try_files $uri $uri/ /index.html; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } } # Vant 子域名配置 server { listen 80; server_name vant.hht.test; access_log /var/log/nginx/vant.access.log main; error_log /var/log/nginx/vant.error.log warn; location / { alias /usr/share/nginx/html/vant/; index index.html index.htm; try_files $uri $uri/ /index.html; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location /vant/ { alias /usr/share/nginx/html/vant/; try_files $uri $uri/ /tparking/index.html; index index.html; # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } } # Vue3 子域名配置 server { listen 80; listen 8877; # 添加 8877 端口监听 server_name vue3.hht.test; # 日志配置 access_log /var/log/nginx/vue3.access.log main buffer=32k flush=5s; error_log /var/log/nginx/vue3.error.log warn; # 安全相关配置 add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; add_header X-Content-Type-Options "nosniff" always; # 性能优化 client_max_body_size 10m; client_body_timeout 12; client_header_timeout 12; keepalive_timeout 15; send_timeout 10; # 字体文件 MIME 类型 include /etc/nginx/mime.types; types { font/woff2 woff2; font/woff woff; font/ttf ttf; font/eot eot; } location / { alias /usr/share/nginx/html/docs-zh-cn/.vitepress/dist/; index index.html index.htm; try_files $uri $uri/ /index.html; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; access_log off; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 禁止访问隐藏文件 location ~ /\. { deny all; access_log off; log_not_found off; } # 禁止访问 .git 目录 location ~ /\.git { deny all; access_log off; log_not_found off; } } # 静态资源缓存优化 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { root /usr/share/nginx/html/docs-zh-cn/.vitepress/dist; expires 7d; add_header Cache-Control "public, no-transform"; access_log off; tcp_nodelay off; open_file_cache max=1000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on; try_files $uri =404; } # 错误页面配置 error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /404.html { internal; } location = /50x.html { internal; } } # 2x ant-design 子域名配置 server { listen 80; server_name 2x-ant-design.hht.test; access_log /var/log/nginx/2x-ant-design.access.log main; error_log /var/log/nginx/2x-ant-design.error.log warn; location / { root /usr/share/nginx/html/2x.ant.design; index index.html index.htm; try_files $uri $uri/ @router; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location @router { rewrite ^.*$ /index.html last; } } # 2x antv-design 子域名配置 server { listen 80; server_name 2x-antv-design.hht.test; access_log /var/log/nginx/2x-antv-design.access.log main; error_log /var/log/nginx/2x-antv-design.error.log warn; location / { root /usr/share/nginx/html/2x.antv.design; index index.html index.htm; try_files $uri $uri/ @router; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location @router { rewrite ^.*$ /index.html last; } } # 3x ant-design 子域名配置 server { listen 80; server_name 3x-ant-design.hht.test; access_log /var/log/nginx/3x-ant-design.access.log main; error_log /var/log/nginx/3x-ant-design.error.log warn; location / { root /usr/share/nginx/html/3x.ant.design; index index.html index.htm; try_files $uri $uri/ @router; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location @router { rewrite ^.*$ /index.html last; } } # 3x antv-design 子域名配置 server { listen 80; server_name 3x-antv-design.hht.test; access_log /var/log/nginx/3x-antv-design.access.log main; error_log /var/log/nginx/3x-antv-design.error.log warn; location / { root /usr/share/nginx/html/3x.antv.design; index index.html index.htm; try_files $uri $uri/ @router; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location @router { rewrite ^.*$ /index.html last; } } # 4x ant-design 子域名配置 server { listen 80; server_name 4x-ant-design.hht.test; # 日志配置 access_log /var/log/nginx/4x-ant-design.access.log main buffer=32k flush=5s; error_log /var/log/nginx/4x-ant-design.error.log warn; # 安全相关配置 add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; add_header X-Content-Type-Options "nosniff" always; # 性能优化 client_max_body_size 10m; client_body_timeout 12; client_header_timeout 12; keepalive_timeout 15; send_timeout 10; # 字体文件 MIME 类型 include /etc/nginx/mime.types; types { font/woff2 woff2; font/woff woff; font/ttf ttf; font/eot eot; } location / { root /usr/share/nginx/html/4x.ant.design; index index.html index.htm; try_files $uri $uri/ @router; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; access_log off; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 禁止访问隐藏文件 location ~ /\. { deny all; access_log off; log_not_found off; } # 禁止访问 .git 目录 location ~ /\.git { deny all; access_log off; log_not_found off; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } # 静态资源缓存优化 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { root /usr/share/nginx/html/4x-ant-design; expires 7d; add_header Cache-Control "public, no-transform"; access_log off; tcp_nodelay off; open_file_cache max=1000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on; try_files $uri =404; } location @router { rewrite ^.*$ /index.html last; } # 错误页面配置 error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /404.html { internal; } location = /50x.html { internal; } } # ant-design 子域名配置 server { listen 80; server_name ant-design.hht.test; access_log /var/log/nginx/ant-design.access.log main; error_log /var/log/nginx/ant-design.error.log warn; location / { root /usr/share/nginx/html/ant-design; index index.html index.htm; try_files $uri $uri/ @router; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location @router { rewrite ^.*$ /index.html last; } } # 1x-ant-design-vue 子域名配置 server { listen 80; server_name 1x-antv-design.hht.test; access_log /var/log/nginx/1x-antv-design.access.log main; error_log /var/log/nginx/1x-antv-design.error.log warn; location / { root /usr/share/nginx/html/1x.antv.design; index index.html index.htm; try_files $uri $uri/ @router; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location @router { rewrite ^.*$ /index.html last; } } # ant-design-vue 子域名配置 server { listen 80; server_name ant-design-vue.hht.test; access_log /var/log/nginx/antv-design.access.log main; error_log /var/log/nginx/antv-design.error.log warn; location / { root /usr/share/nginx/html/ant-design-vue/site/dist/; index index.html index.htm; try_files $uri $uri/ @router; # 针对不同类型的文件设置不同的缓存时间 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 7d; add_header Cache-Control "public, no-transform"; } location ~* \.(html|htm)$ { expires 1h; add_header Cache-Control "public, no-transform"; } # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location @router { rewrite ^.*$ /index.html last; } } # better-scroll 子域名配置 server { listen 80; server_name better-scroll-docs.hht.test; location / { #root /Users/sysadmin/code/vue_project/better-scroll-docs/zh-CN; #index index.html index.htm; alias /usr/share/nginx/html/better-scroll-docs/zh-CN/; try_files $uri $uri/ /index.html; index index.html; add_header Access-Control-Allow-Origin *; } location /docs/ { alias /usr/share/nginx/html/better-scroll-docs/; #try_files $uri $uri/ /tparking/index.html; #index index.html; #add_header Access-Control-Allow-Origin *; } } # tauri-docs 子域名配置 server { listen 80; server_name tauri-docs.hht.test; location / { #root /Users/sysadmin/code/vue_project/better-scroll-docs/zh-CN; #index index.html index.htm; alias /usr/share/nginx/html/tauri-docs/dist/; try_files $uri $uri/ /index.html; index index.html; add_header Access-Control-Allow-Origin *; } } # 1x-tauri-docs 子域名配置 server { listen 80; server_name 1x-tauri-docs.hht.test; location / { #root /Users/sysadmin/code/vue_project/better-scroll-docs/zh-CN; #index index.html index.htm; alias /usr/share/nginx/html/tauri-docs-v1/build/; try_files $uri $uri/ /index.html; index index.html; add_header Access-Control-Allow-Origin *; } } # electron-website 子域名配置 server { listen 80; server_name electron-website.hht.test; location / { #root /Users/sysadmin/code/vue_project/better-scroll-docs/zh-CN; #index index.html index.htm; alias /usr/share/nginx/html/electron-website/build/; try_files $uri $uri/ /index.html; index index.html; add_header Access-Control-Allow-Origin *; } location /zh/ { alias /usr/share/nginx/html/electron-website/build/; try_files $uri $uri/ /index.html; index index.html; # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location /docs/ { alias /usr/share/nginx/html/electron-website/build/; try_files $uri $uri/ /index.html; index index.html; # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } location /apps/ { alias /usr/share/nginx/html/electron-website/build/; try_files $uri $uri/ /index.html; index index.html; # 跨域支持 add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } } # 默认服务器配置 server { listen 80 default_server; server_name _; return 404; } }