一、设置http反向代理:
upstream ly.com {server 192.168.1.100:88;server 192.168.1.101:88;}upstream home.ly.com {server 192.168.1.100:90;server 192.168.1.101:90;}
对应增加:
server {listen 80;server_name ly.com;location / {proxy_pass http://ly.com;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Cookie $http_cookie;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}
和
server {listen 80;server_name home.ly.com;location / {proxy_pass http://home.ly.com;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Cookie $http_cookie;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}
二、配置ssl:
先开启nginx所在服务器443端口。
申请证书,阿里云有免费的证书可供使用,会提供一个key文件和一个pem文件。将证书放在conf目录下。
如果是整站https而不允许http的情况下可如下设置:
server {listen 80;listen 443;ssl on;ssl_certificate 214****.pem;ssl_certificate_key 214****.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;ssl_prefer_server_ciphers on;
如果要共存只需将前三行改成:
server {listen 80;listen 443 ssl;#ssl on;
意思是只有443端口是https方式80端口还是http方式访问。
另开启了ssl,网站就不能有非https的资源引用了。
nginx的https和http共存反向代理配置
原文地址:http://www.cnblogs.com/madyina/p/7735545.html