- 配置静态文件
location / {
root /usr/local/web;
try_files $uri /index.html
index index.html index.htm;
}
- 配置动态文件
location /netsec/ {
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;
proxy_pass http://127.0.0.1:5000/;
index index.html index.htm;
}
- 配置websocket
location /ws/ {
#添加wensocket代理
proxy_pass http://127.0.0.1:5008/; # websocket服务器。不用管 ws://
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
4.配置mysql反向代理
server {
listen 8017;
proxy_connect_timeout 10s;
proxy_timeout 525600m;
proxy_pass ip:3306;
}
server {
listen 8012;
proxy_connect_timeout 10s;
proxy_timeout 525600m;
proxy_pass ip:3306;
}
nginx.conf中引入mysql的配置文件
stream {
include mysql.conf;
}
- 配置websocket代理
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream wsbackend{
server ip1:port1;
server ip2:port2;
keepalive 1000;
}
server {
listen 20038;
location /{
proxy_http_version 1.1;
proxy_pass http://wsbackend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 3600s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
- 下载文件
#root alias 区别 root直接加到路径的后边 alias直接将原url路径替换掉
location /download/video/ {
alias /mnt/data/video/; #下载地址
add_header Content-Disposition attachment;
autoindex on; #开启索引功能
autoindex_exact_size off; #关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
autoindex_localtime on; # 显示本机时间而非 GMT 时间
error_page 404 403 https://ip:8443/$request_uri;
}