我最近在 debian 8 上创建了一个 nginx 服务器。它在/etc/nginx/sites-available/default 上提供了一个默认配置,它重定向到一个 nginx 欢迎页面。
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name your_server_ip;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
我添加了一个新的生产页面,比如上面带有 ssl 的“example.com”。
在 ../example.com 的配置中,它没有被设置为默认服务器。
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
# SSL configuration
listen 443 ssl;
listen [::]:443 ssl;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
....
现在,当我在 https://www.ssllabs.com/ssltest/analyze.html?d=example.com 上对其进行 SSL 安全测试时,它获得了 A+。但它评论了“不一致的服务器配置”。
当我加载 IP 地址时,在浏览器上将 x.x.x.x 设为 https://x.x.x.x它加载与 https://example.com 相同的页面但上面没有 ssl(绿色地址栏)。如果我加载http://x.x.x.x它加载默认的 nginx 欢迎页面。
我尝试设置默认配置(用于 ip)以获取禁止消息,我添加了以下代码
location / {
deny all;
}
现在,当我对 example.com 进行 SSL 安全测试时,它显示“不支持安全协议(protocol)”并且没有出现测试结果。
所以我的问题是,
nginx自带的加载ip地址的默认配置应该怎么办?
哪个 server_name(配置文件)应该设置为“listen”命令的 default_server?
应该如何处理当前正在将 https 请求转发到示例域的 ip?
预期结果:-
https://example.com仅应用于连接到服务器并加载 ip 地址可以显示“找不到页面”或“禁止访问”,因为 example.com 将用于其上的 php 脚本。
SSL 测试应在设置配置后至少给出 A 评级。
ip地址不应该直接接受任何连接并处理它。
最佳答案
默认配置显然不提供 SSL。通常,您需要安装 SSL 证书。有很多这方面的教程。您网页的入口点由您决定。您在同一个帖子中提出不同的问题。
显然,您可以在这里和其他地方通过搜索找到答案。
关于linux - 在 nginx 中处理默认服务器和 ip 转发的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43741824/