1、最外层
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
sendfile on;
#tcp_nopush on;
server_tokens off;
keepalive_timeout 65;
client_max_body_size 100m;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
2、http
server {
listen 80;
listen [::]:80;
server_name localhost;
add_header X-Content-Type-Options nosniff;
add_header 'Referrer-Policy' 'origin';
add_header X-Download-Options "noopen" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header X-Permitted-Cross-Domain-Policies "master-only";
add_header X-Content-Type-Options: nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options ALLOWALL;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
root /usr/share/nginx/html/web-site/dist;
try_files $uri $uri/ @router-index;
index index.html index.htm;
}
location /hanvon-web/ {
proxy_buffering off;
proxy_pass http://192.168.0.1:15004/hanvon-web/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /hanvon-app/ {
proxy_buffering off;
proxy_pass http://192.168.0.1:15005/hanvon-app/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
3、https
server {
listen 443 ssl;
#listen 443 default ssl http2 fastopen=3;
server_name wlgs.tjbfhw.com;
ssl_certificate /etc/nginx/conf.d/cert/9048546_develop.tjbfhw.com.pem;
ssl_certificate_key /etc/nginx/conf.d/cert/9048546_develop.tjbfhw.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
if ($host != 'wlgs.tjbfhw.com' ) {
return 403;
break;
}
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods GET,POST;
add_header 'Referrer-Policy' 'origin';
add_header X-XSS-Protection 1;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header X-Frame-Options SAMEORIGIN;
server_tokens off;
#access_log D:/prod_env/runtime/logs/nginx/host.access.log main;
location / {
root html;
index index.html index.htm;
#解决vue刷新404问题
try_files $uri $uri/ @router-index;
index index.html index.htm;
}
location @router-index {
rewrite ^.*$ /index.html last;
}
# hanvon-app-gateway网关
location /hanvon-app/ {
proxy_buffering off;
proxy_pass http://192.168.0.1:15005/hanvon-app/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# hanvon-web-gateway网关
location /hanvon-web/ {
proxy_buffering off;
proxy_pass http://192.168.0.1:15004/hanvon-web/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
error_page 404 /404.html;
location = /404.html {
root html;
}
}