nginx之错误url重定向到首页
1、配置:
[[email protected] ~]# vi test.conf server { listen 443 ssl; listen 80; server_name www.magedu.org; root /data/site14/; #ssl on; ssl_certificate /apps/nginx4/ssl/magedu.org.crt; ssl_certificate_key /apps/nginx4/ssl/magedu.org.key; ssl_session_cache shared:sslcache:20m; ssl_session_timeout 10m; access_log /apps/nginx4/logs/magedu.org.ssl.access.log access_json ; location / { if ( !-e $request_filename) { rewrite ^(.*)$ https://www.magedu.org ; } if ($scheme = http) { rewrite ^/(.*)$ https://www.magedu.org/$1 permanent; } } }
2、验证
[[email protected] ~]# curl -I http://www.magedu.org HTTP/1.1 301 Moved Permanently Server: nginx/1.14.2 Date: Mon, 08 Mar 2021 12:07:41 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: https://www.magedu.org/ [[email protected] ~]# curl -Lk http://www.magedu.org /data/site14/index.html [[email protected] ~]# curl -I http://www.magedu.org/fffffff.tml HTTP/1.1 302 Moved Temporarily Server: nginx/1.14.2 Date: Mon, 08 Mar 2021 12:08:13 GMT Content-Type: text/html Content-Length: 161 Connection: keep-alive Location: https://www.magedu.org [[email protected] ~]# curl -Lk http://www.magedu.org/fffffff.tml /data/site14/index.html
标签:www,ssl,url,magedu,nginx,首页,org,root,centos7.6 From: https://www.cnblogs.com/cnblogsfc/p/14592048.html