nginx之错误url重定向到首页

nginx之错误url重定向到首页

1、配置:

[root@centos7.6 ~]# 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、验证

[root@centos7.6 ~]# 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/

[root@centos7.6 ~]# curl -Lk http://www.magedu.org
/data/site14/index.html



[root@centos7.6 ~]# 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

[root@centos7.6 ~]# curl -Lk http://www.magedu.org/fffffff.tml
/data/site14/index.html

 

posted @ 2024-08-29 09:12  起点·漫步前行  阅读(83)  评论(0)    收藏  举报