【发布时间】:2022-11-23 18:45:47
【问题描述】:
我正在努力让两个域通过 NGINX 在 digitalocean.com 托管(在 Ubuntu 20,04 Droplet 中)上正确提供服务。我们称它们为 domain1.com(默认)和 domain2.com。 domain1.com 工作正常并且有 SSL(来自 Let's Encrypt),此时 domain2 只是 http。
domain2.com 的主页现在加载正常,使用这个服务器块:
server {
listen *:80;
listen [::]:80;
root /home/domain2/;
index index.html;
server_name domain2.com www.domain2.com;
location / {
try_files $uri $uri/ =404;
}
}
但是,当我导航到 domain2.com 站点上的另一个页面时,它会加载默认站点 domain1.com。很奇怪在 Chrome 地址行中看到 domain2.com,同时出现 domain1.com 网页。
我认为这与默认的 domain1.com 有关,但我不知道为什么会这样。我是 NGINX 的新手......我应该怎么做才能解决这个问题?
/etc/nginx/sites-available 中的默认文件具有以下内容:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/domain1/server/public;
index index.js index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
root /home/domain1/server/public;
index index.js index.html index.htm index.nginx-debian.html;
server_name domain1.com; # managed by Certbot
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/intraprem.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/intraprem.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = domain1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name domain1.com;
return 404; # managed by Certbot
}
【问题讨论】:
标签: nginx-reverse-proxy ubuntu-20.04