NGINX语法
#负载均衡
upstream test_upstream{
server 192.168.7.167:8080;
server 192.168.7.173:8080;
server 192.168.7.121:8080;
}
# 配置down表示停用 server 192.168.7.137:12002 down;
upstream management-platform_upstream{
server 192.168.7.137:12001;
server 192.168.7.137:12002;
}
upstream management-platform_web_upstream{
server 192.168.7.137:80;
server 192.168.7.137:81 down;
}
#主机,可以配置多个
server {
listen 80;
#开启https
listen 443 ssl;
server_name online.rgsc.com.cn;
#http 自动跳转 https
error_page 497 https://$server_name:8099$request_uri;
#ssl证书配置,阿里云提供
ssl_certificate pem文件路径;
ssl_certificate_key key文件路径;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
#表示使用的加密套件的类型。
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
ssl_prefer_server_ciphers on;
#综合管理平台测试环境web
#最后找不到的都转发这里
location / {
proxy_pass http://management-platform_web_upstream;
#携带协议头
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# root /usr/share/nginx/html;
#打开自动索引index页
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
index index.html index.htm;
}
location /test {
proxy_pass http://192.168.7.165:80;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
index index.html index.htm;
}
#综合管理平台测试环境接口
location /management-platform {
proxy_pass http://management-platform_upstream;
add_header OP_TYPE TEST;
add_header PLATFORM_TYPE MANAGEMENT;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location /api {
proxy_pass http://192.168.7.22:9090;
add_header OP_TYPE TEST;
add_header PLATFORM_TYPE ASSIGN;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location /bookstore {
#注意 有斜杠
proxy_pass http://192.168.7.166:8080/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
#添加生产响应头信息
add_header USER_TYPE PRO;
if ( $remote_addr = "192.168.8.1" ){
#添加测试响应头信息
add_header USER_TYPE TEST;
#注意 无 斜杠,这里有斜杠报错 ,if中使用正则 只能转发ip+端口不能带其他东西
proxy_pass http://test_upstream;
break;
}
}
#zabbix获取status
location = /basic_status {
stub_status;
allow 127.0.0.1;
allow ::1;
deny all;
}
location /echo {
echo "hello world" $remote_addr $server_addr;
default_type text/html;
}
}