txw/devops/web/nginx.conf
2026-05-03 17:49:17 +08:00

165 lines
4.8 KiB
Nginx Configuration File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

worker_processes auto;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 8192;
use epoll;
multi_accept on;
}
http {
# 日志格式
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;
# 基础配置
client_max_body_size 100m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# Gzip 压缩http 级别)
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/x-javascript
text/xml application/xml application/xml+rss
application/javascript text/javascript
application/vnd.ms-fontobject application/x-font-ttf
font/opentype image/svg+xml image/x-icon;
# 代理超时配置
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
send_timeout 300s;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# =============================================
# 主 Server 块
# =============================================
server {
listen 80 default_server;
absolute_redirect off;
server_name _;
# Gzip 压缩server 级别,微调)
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript
application/x-javascript text/xml application/xml
application/xml+rss text/javascript image/svg+xml;
# 健康检查
location /healthcheck {
access_log off;
return 200 'OK';
add_header Content-Type text/plain;
}
# Ping 接口
location /ping {
return 200 "ok";
}
# API 代理(网关)
location ~ ^/(mhzc|gxzx|sso|yygl) {
include proxy-common.conf;
proxy_pass http://txw-gateway:9300;
}
# 百度验证
location = /baidu_verify_codeva-5rH3psCeMQ.html {
alias /etc/nginx/verify/baidu_verify_codeva-5rH3psCeMQ.html;
}
location = /baidu_verify_codeva-eE1giHswVL.html {
return 200 "2c7cc0bcf0ecd060ab8f7fe919acc078";
add_header Content-Type text/html;
}
# --------------------------------------------------------
# 运营支撑前端mhzc
# --------------------------------------------------------
location /view/mhzc {
return 301 /view/mhzc/;
}
location /view/mhzc/ {
alias /usr/share/nginx/html/txw-mhzc-web/;
# 静态资源90天缓存
location ~* \.(gif|jpg|jpeg|png|css|js|ico|eot|svg|ttf|woff|woff2)$ {
expires 90d;
add_header Cache-Control "public";
try_files $uri =404;
}
# 非静态资源1小时缓存
expires 1h;
add_header Cache-Control "public";
try_files $uri $uri/ /view/mhzc/index.html;
}
# --------------------------------------------------------
# 运营管理前端yygl
# --------------------------------------------------------
location /view/yygl {
return 301 /view/yygl/;
}
location /view/yygl/ {
alias /usr/share/nginx/html/txw-yygl-web/;
# 静态资源90天缓存
location ~* \.(gif|jpg|jpeg|png|css|js|ico|eot|svg|ttf|woff|woff2)$ {
expires 90d;
add_header Cache-Control "public";
try_files $uri =404;
}
# 非静态资源1小时缓存
expires 1h;
add_header Cache-Control "public";
try_files $uri $uri/ /view/yygl/index.html;
}
# --------------------------------------------------------
# 默认首页重定向
# --------------------------------------------------------
location / {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
return 301 /view/mhzc/;
}
# 错误页面
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# 引入其他 location 配置
include ./location.d/*.conf;
}