这篇文章主要介绍了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; #注意看这里 多了一行
}
}