403禁止重定向到主页

时间:2018-03-01 21:11:13

标签: php redirect nginx

我正在尝试将 403 Forbidden 请求重定向到我们网站的主页(index.php)。收到403错误消息的示例网址是此网址: https://www.acme.com/dr/mellow/ 。我尝试将以下行添加到配置文件中:error_page 403 /index.php;。当我这样做时,我不再收到403 Forbidden消息,我只收到一个空白页面。我只是想重定向到/index.php。我目前正在运行NGINX服务器。这是我的配置文件:

server {
    server_name acme.com;
    return 301 $scheme://www.acme.com$request_uri;
}

server {
    listen 80;
    server_name www.acme.com;

    #BEGIN SSL
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/acme.com.chained.crt;
    ssl_certificate_key /etc/nginx/ssl/acme.com.key;

    # Makes for the most secure connections
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
    #END SSL

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ $uri.html $uri.php?$query_string;
    }

    error_page 403 =200 /index.php;
    error_page 404 /index.php;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    ##BEGIN ALLOWING LARGE UPLOADS##
    client_max_body_size 100M;

    ## BEGIN CACHING SETTINGS ##
    # Media: images, icons, video, audio, fonts, HTC
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff)$ {
        expires 30d;
        access_log off;
        add_header Cache-Control "public";
    }

    # CSS and Javascript
    location ~* \.(?:css|js)$ {
        expires 30d;
        access_log off;
        add_header Cache-Control "public";
    }
    ## END CACHING SETTINGS ##
}

0 个答案:

没有答案