nginx 不同二级域名指向不同页面的问题。
各位大佬,我有个问题想请教一下:我的 www.mydomain.cn 官网页面 nginx 指到 http://127.0.0.1:8181
我有a、b、c、三个二级域名,想达到如下效果:
a.mydomain.cn 访问 http://127.0.0.1:8181/a.html
b.mydomain.cn 访问 http://127.0.0.1:8181/b.html
c.mydomain.cn 访问 http://127.0.0.1:8181/c.html
请问在nginx里如何设置实现? 下面是我现在nginx设置:
server {
listen172.16.100.5:80;
server_namewww.mydomain.cn;
rewrite ^ https://$http_host$request_uri? permanent; #强制将http重定向到https
server_tokens off;
}
server {
listen 172.16.100.5:443ssl;
ssl_certificate /usr/local/nginx/conf/ssl/*.mydomain.cn/*.mydomain.cn.cer; #cacert.pem 文件路径
ssl_certificate_key /usr/local/nginx/conf/ssl/*.mydomain.cn/*.mydomain.cn.key; #privkey.pem 文件路径
server_name www.mydomain.cn;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:5m;
# Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
# ssl_dhparam /etc/nginx/dhparam.pem;
# secure settings (A+ at SSL Labs ssltest at time of writing)
# see https://wiki.mozilla.org/Security/Server_Side_TLS#Nginx
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-CAMELLIA256-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-SEED-SHA:DHE-RSA-CAMELLIA128-SHA:HIGH:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS';
ssl_prefer_server_ciphers on;
proxy_set_header X-Forwarded-For $remote_addr;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
server_tokens off;
location / {
proxy_pass http://127.0.0.1:8181;
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 X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout1200s;
access_log /home/wwwlogs/access.log;
error_log /home/wwwlogs/nginx_error.log;
}
}
没遇到过这种需求,不确定是否可以,你自己可以尝试以下
在a域名对应的server段的location 里面加上 index a.html;
在b域名对应的server段的location 里面加上 index b.html;
依次类推 这种方法我试验过,没有成功:(
页:
[1]