1、代理转发
1.1)两个项目用同一个域名
server {
listen 80;
server_name 域名;
location / {
proxy_pass http://127.0.0.1:8055/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_set_header Host $host;
}
location /bb {
proxy_pass http://127.0.0.1:8066/bb;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_set_header Host $host;
}
}
1.2)两个项目2个域名
server {
listen 80;
server_name 域名1;
location /{
proxy_pass http://127.0.0.1:8055/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name 域名2;
location /{
proxy_pass http://127.0.0.1:8066/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_set_header Host $host;
}
}
3、代理转发+ssl,同一个域名(注意443端口的放行)
server {
listen 80;
server_name 域名;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443 ssl;
server_name 域名;
ssl_certificate /ssl/xxx.crt;
ssl_certificate_key /ssl/xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /aa {
proxy_pass http://127.0.0.1:8055/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_set_header Host $host;
}
location /bb {
proxy_pass http://127.0.0.1:8066/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_set_header Host $host;
}
}
4、代理转发+ssl,不同域名
server {
listen 80;
server_name 域名1;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443 ssl;
server_name 域名1;
ssl_certificate /ssl/xxx.crt;
ssl_certificate_key /ssl/xxx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:8055/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name 域名2;
location / {
proxy_pass http://127.0.0.1:8066/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
proxy_set_header Host $host;
}
}