nginx配置只允许安全域名访问,禁止ip访问

为了避免其他人把未备案的域名解析到自己的服务器IP,而导致服务器被断网,我们可以通过禁止使用ip访问的方法,防止此类事情的发生。

1.首先修改nginx.conf中server中关于80端口的内容:

server {
    listen       80;
	server_name test.ngrok.jcmos.com;
	rewrite ^(.*)$ https://test.ngrok.jcmos.com$1 permanent;

当浏览器 http://test.ngrok.jcmos.com 时会自动跳转到 https://test.ngrok.jcmos.com

2.修改nginx.conf中server中关于443端口的内容:

   server {
        listen       443 ssl;
        server_name  cnpa.anmumchina.com;
	 if ($host = '172.20.42.10'){
                rewrite ^(.*)$ https://test.ngrok.jcmos.com$1 permanent;
        }	
        ssl_certificate     cert/cert-1542683591637_test.ngrok.jcmos.com.crt;
        ssl_certificate_key cert/cert-1542683591637_test.ngrok.jcmos.com.key;
	
	    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   	    ssl_prefer_server_ciphers on;
    }

当浏览器 http://172.20.42.10 时会自动跳转到 https://test.ngrok.jcmos.com

发布了50 篇原创文章 · 获赞 85 · 访问量 161万+

猜你喜欢

转载自blog.csdn.net/qq_24347541/article/details/89475722
今日推荐