利用nginx的localtion属性 来匹配不同的请求,分发到不同的后台地址。
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
# 你的服务器域名
server_name www.xxxxxxxx.com;
root /usr/share/nginx/html;
ssl_certificate "/etc/pki/Nginx/1_xxxxxxxxxx.com_bundle.crt";
ssl_certificate_key "/etc/pki/Nginx/2_xxxxxxxxxx.com.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /api1 {
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 X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://127.0.0.1:3030/api1;
proxy_redirect default;
}
location /api2 {
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 X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://127.0.0.1:3000/api2;
proxy_redirect default;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}