|
在开启SSL是设置的默认站点通过IP访问不是默认站点。 在未开启虚拟主机的情况下: 在网站——设置【ip访问到的站点】——配置文件中修改 这是宝塔面板安全设置里面缺少的一部分,如果我们没有选择默认站点的时候,通过IP地址可以直接访问我们的网站,这样很有可能导致我们的网站被恶意解析了,宝塔面板的Web服务器有两种,分别是Apache和Nginx。下面为大家分享宝塔面板Apache和Nginx服务器禁止通过IP直接访问我们网站的方法。通常我们的网站服务器分为80端口(HTTP)和443(HTTPS)端口。 Apache http禁止通过IP直接访问网站安全配置方法- #NameVirtualHost xx.xxx.xxx.xx
- <VirtualHost *:80>
- ServerName xx.xxx.xxx.xx
- ServerAlias xx.xxx.xxx.xx
- <Location />
- Order Allow,Deny
- Deny from all
- </Location>
- </VirtualHost>
复制代码 Apache https禁止通过IP直接访问网站安全配置方法
- #NameVirtualHost xx.xxx.xxx.xx
- <VirtualHost *:443>
- ServerName xx.xxx.xxx.xx
- ServerAlias xx.xxx.xxx.xx
- SSLEngine on
- SSLProtocol all -SSLv2 -SSLv3
- SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
- SSLHonorCipherOrder on
- SSLCertificateFile /etc/letsencrypt/live/zszx.top/fullchain.pem
- SSLCertificateKeyFile /etc/letsencrypt/live/zszx.top/privkey.pem
- SSLCertificateChainFile /etc/letsencrypt/live/zszx.top/fullchain.pem
- #上面两条SSL证书的路径要换成你自己的路径,把zszx.top修改成你的网站存放的文件夹
- <Location />
- Order Allow,Deny
- Deny from all
- </Location>
- </VirtualHost>
复制代码 证书对应放置:
SSLCertificateFile /etc/letsencrypt/live/zszx.top/www.***.com_public.crt
SSLCertificateKeyFile /etc/letsencrypt/live/zszx.top/www.***.com.key
SSLCertificateChainFile /etc/letsencrypt/live/zszx.top/www.q***.com_chain.crt
Nginx http禁止通过IP直接访问网站安全配置方法
- server
- {
- listen 80 default;
- return 403;
- }
复制代码 Nginx http和https禁止通过IP直接访问网站安全配置方法
- server
- {
- listen 80 default;
- listen 443 default_server;
- server_name _;
- return 403;
- #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
- #error_page 404/404.html;
- ssl_certificate /etc/letsencrypt/live/zszx.top/fullchain.pem;
- ssl_certificate_key /etc/letsencrypt/live/zszx.top/privkey.pem;
- #上面两条SSL证书的路径要换成你自己的路径,把3zszx.top修改成你的网站存放的文件夹
- ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
- ssl_ciphers ECDHE-RSA-AES128-GCM-
- SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
- ssl_prefer_server_ciphers on;
- ssl_session_cache shared:SSL:10m;
- ssl_session_timeout 10m;
- error_page 497 https://$host$request_uri;
- #SSL-END
- }
复制代码 以上的宝塔面板设置Apache和Nginx禁止通过IP直接访问网站的安全设置,配置都是基于宝塔面板的Apache和Nginx的配置文件文件中操作,如不清楚的可以参考上图。配置时以防出错,请提前做好备份。
|