【发布时间】:2016-08-18 10:15:33
【问题描述】:
我有 2 个域在 DigitalOcean Droplet 上使用 nginx 运行
Domain1 是一个节点应用代理传递到 localhost:3000。 效果很好!
Domain2 是一个运行良好的静态站点。
但是,每当我加载服务器 IP(没有端口 3000)时,我总是被重定向到 domain1(节点应用程序)。
Domain1 是一种私人网站,而 domain2 是公共博客。
我的问题是,当人们加载 IP 时,我必须进行哪些更改才能将其重定向到 domain2,以保护 domain1 不被轻易访问。 (VPS IP很容易查到)
这里是“站点可用”文件:
节点应用:
server {
listen [::]:80;
listen 80;
server_name www.domain1.com domain1.com;
# and redirect to the https host (declared below)
return 301 https://domain1.com$request_uri;
}
server {
listen 443;
server_name domain1.com www.domain1.com;
ssl on;
# Use certificate and key provided by Let's Encrypt:
ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3000/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
还有静态的:
server {
listen [::]:80;
listen 80;
server_name www.domain2.com domain2.com;
root /var/www/html/domain2;
index index.html index.htm;
return 301 https://domain2.com$request_uri;
}
server {
listen [::]:443 ssl;
listen 443 ssl;
root /var/www/html/domain2;
index index.html index.htm;
ssl_certificate /etc/letsencrypt/live/domain2.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain2.com/privkey.pem;
}
感谢任何帮助/提示,在此先感谢您!
【问题讨论】: