123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- 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;
- }
- }
-
- # 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;
- }
- }
- # 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;
- }
- }
-
- # 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;
- }
- }
-
- # ant-design-vue 子域名配置
- server {
- listen 80;
- server_name ant-design-vue.hht.test;
- access_log /var/log/nginx/ant-design-vue.access.log main;
- error_log /var/log/nginx/ant-design-vue.error.log warn;
-
- location / {
- root /usr/share/nginx/html/ant-design-vue;
- 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 *;
- }
-
- }
- # 默认服务器配置
- server {
- listen 80 default_server;
- server_name _;
- return 404;
- }
- }
|