后端端口
后端项目一端口: 81
后端项目二端口: 82
后端项目三端口: 83
域名
目的
https://api.example.com/project1/ ==> http://127.0.0.1:81/
https://api.example.com/project2/ ==> http://127.0.0.1:82/
https://api.example.com/project3/ ==> http://127.0.0.1:83/
Nginx配置
root@ls-cloudlab:~# cat /etc/nginx/conf.d/api.conf
server {
listen 443; # 修改端口为443
server_name api.example.com;
client_max_body_size 100M;
# 获取经过Nginx转发的访问来源真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
# 开启ssl认证
ssl on;
ssl_certificate cert/api/api.example.com.pem; #.pey文件相对路径
ssl_certificate_key cert/api/api.example.com.key; # .key文件相对路径
ssl_session_timeout 10m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
# 转发
location /project1/ {
proxy_pass http://127.0.0.1:81/;
}
location /project2/ {
proxy_pass http://127.0.0.1:82/;
}
location /project3/ {
proxy_pass http://127.0.0.1:83/;
}
}
网友评论