1、nginx调转
m.xxxx.com
nginx配置从 /carnival/imgShare/738 跳转到 /helper/questionPage?questionId=329
location ^~ /carnival/imgShare/738 {
rewrite ^ http://m.xxx.com/helper/questionPage?questionId=329;
}
2、nginx
域名http://static2.test.xxx.com/yx/open-idea-manage/last/build/#/!F1-index
location /yx/open-idea-manage/last/build/ {
rewrite ^ http://cms.test.xxx.com/open-idea-manage/#/!F1-index;
}
location /open-idea-manage/ {
rewrite ^ http://static2.test.xxx.com/yx/open-idea-manage/last/build/index.html;
}
3、nginx rewrite
的相关配置
rewrite /live/room/([0-9]+) https://m.test.xxx.com/gatekeeper/live-room-h5?roomId=$1 permanent;
4、nginx跨域访问
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Origin' *;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
5、nginx强制跳转https
server {
listen 80;
listen 443 ssl;
client_max_body_size 4G;
server_name a2.test.xxx.com;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
#proxy_set_header If-Range $http_x_if_range;
#proxy_set_header Range $http_x_range;
access_log /logs/http/a2.access.log main;
# error_page 404 /404.html;
#######下边是强制由http跳转到HTTPS
if ($scheme = "http") {
rewrite ^ https://$host$request_uri? permanent;
}
}
6、nginx某一个uri应用调整其他域名
location ^~ /xunicorn {
rewrite ^/xunicorn/(.*) http://ops.xxx.com/unicorn-server/$1 permanent;
rewrite ^/(.*) http://ops.xxxx.com/unicorn-server/index permanent;
}
7、nginx的upstream监控检查配置说明
check interval=3000 rise=2 fall=3 timeout=2000 type=http;
check 字段各个参数含义如下:
interval:向后端发送的健康检查包的间隔,单位为毫秒。
fall(fall_count): 如果连续失败次数达到fall_count,服务器就被认为是down。
rise(rise_count): 如果连续成功次数达到rise_count,服务器就被认为是up。
timeout: 后端健康请求的超时时间。
default_down: 设定初始时服务器的状态,如果是true,就说明默认是down的,如果是false,就是up的。
默认值是true,也就是一开始服务器认为是不可用,要等健康检查包达到一定成功次数以后才会被认为是健康的。
type:健康检查包的类型,现在支持以下多种类型
tcp:
简单的tcp连接,如果连接成功,就说明后端正常。
ssl_hello:
发送一个初始的SSL hello包并接受服务器的SSL hello包。
http:
发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。
8、nignx域名重定向另外一个域名
####域名 www.test123.com 跳转到www.test456.com
server {
listen 80;
server_name www.test123.com;
rewrite ^/(.*) http://www.test456.com/$1 permanent;
9、代理超时时间配置
location / {
proxy_connect_timeout 600s;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_pass http://nacos_registry_bs;
}