我有服3子域的nginx的服务器-比如说a.example.com,b.example.com和c.example.com。
该配置文件a.example.com.conf,b.example.com.conf和c.example.com.conf分别。它们存储在/etc/nginx/sites-available从软链接/etc/nginx/sites-enabled。
在配置文件中,每个server子句都有其相应的server_name指令。如果重要的话,所有三个子域都使用Let's Encrypt 发出的相同SSL 证书问题(工作正常)。
当b.example.com.conf从 中删除时sites-enabled,我希望在尝试浏览它时出现错误消息。令人惊讶的是,nginx 将流量重定向到a.example.com. 事实上,每个没有匹配服务器名称的传入连接/etc/nginx/sites-enabled- 仅包括机器 IP - 都被路由到a.example.com.
如何配置 nginx 以使server指令独占,以便b.example.com永远不会为 提供服务a.example.com?
a.example.com.confserver {
listen 443 ssl;
server_name a.example.com;
ssl_certificate /etc/letsencrypt/live/a.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/a.example.com/privkey.pem;
location / {
proxy_pass http://localhost:8080;
}
}
Run Code Online (Sandbox Code Playgroud)
b.example.com.confserver {
listen 443 ssl;
server_name b.example.com;
# I'm using a multi-domain certificate called `a.example.com`, which is
# serving a.example.com, b.example.com and c.example.com - not an error
ssl_certificate /etc/letsencrypt/live/a.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/a.example.com/privkey.pem;
location / {
proxy_pass http://localhost:8090;
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个默认服务器来捕获所有默认请求并返回错误 404。但是,我想要一个更全面的解决方案,以防止来自另一台服务器服务的任何给定服务器的请求。
server {
listen 443 default_server;
server_name _;
return 404;
ssl_certificate /etc/letsencrypt/live/a.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/a.example.com/privkey.pem;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
134 次 |
| 最近记录: |