Nginx实现域名分发与https分发配置

这篇文章主要介绍了Nginx实现根据域名http、https分发配置示例

不同域名 face.chendongmei.com、demo.chendongmei.com、cesium.chendongmei.com,指向同一台云服务器。

nginx文件配置

nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
	
	include chendongmei/*.conf;
}

创建一个目录chendongmei,三个个文件cesium.chendongmei.com.conf、demo.chendongmei.com.conf、face.chendongmei.com.conf。

普通http分发配置

cesium.chendongmei.com

server {
	listen 80;
	server_name cesium.chendongmei.com;
	
	location / {
		proxy_pass http://127.0.0.1:8080;
		proxy_set_header Host $host:80;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Via "nginx";
	}
}

face.chendongmei.com

server {
	listen 80;
	server_name face.chendongmei.com;
	
	location / {
		proxy_pass http://127.0.0.1:8081;
		proxy_set_header Host $host:80;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Via "nginx";
	}
}

https分发配置

	server {
        listen 443;
        server_name demo.chendongmei.com;
        ssl on;
        ssl_certificate 1_demo.chendongmei.com_bundle.crt;
        ssl_certificate_key 2_demo.chendongmei.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
        ssl_prefer_server_ciphers on;
        
        set $distPath /home/www/;
		root $distPath;

    }
    
    server {
        listen 80;
        server_name demo.chendongmei.com;
		
		location / {
			proxy_pass https://127.0.0.1:443;
			proxy_set_header Host $host:443;
			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 X-Forwarded-Proto https; #注意看这里 多了一行
		}
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值