主配置文件
#启动用户
user nginx;
#worker 进程数
worker_processes auto;
#ERROR日志路径
error_log /var/log/nginx/error.log;
#进程pid文件
pid /run/nginx.pid;
#引入模块配置
include /usr/share/nginx/modules/*.conf;
events {
#连接数,实际支持最大连接数 worker_connections*worker_processes
worker_connections 1024;
}
http {
#定义日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$upstream_addr';
#日志配置
access_log /var/log/nginx/access.log main;
#websocket需要配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
#content-type 对应媒体文件格式映射
include /etc/nginx/mime.types;
#默认content-type
default_type application/octet-stream;
#引入其他的配置文件
include /etc/nginx/conf.d/*.conf;
}
server 配置
#定义转发地址
upstream portal_server {
server *.*.*.1:8088;
server *.*.*.2:8088;
#负载策略
ip_hash;
}
server {
#监听80端口,默认的server
listen 80 default_server;
#域名
server_name ***.bimuyu.tech;
#主目录
root /home/***/web;
#VUE相关配置
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router{
rewrite ^.*$ /index.html last;
}
#代理后台接口
location /api/ {
#转发
proxy_pass http://portal_server/;
#定义请求头
proxy_set_header Host $host:$server_port;
#websocket需要配置 心跳等待时间
proxy_http_version 1.1;
proxy_connect_timeout 4s; #配置点1
proxy_read_timeout 600s; #配置点2,如果没效,可以考虑这个时间配置长一点
proxy_send_timeout 600s; #配置点3
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
#error页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}