首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx 414 HTTP错误,301重定向破坏了我的网站

nginx 414 HTTP错误,301重定向破坏了我的网站
EN

Server Fault用户
提问于 2018-03-23 20:20:34
回答 1查看 476关注 0票数 0

我想做一个301重定向形式: www.kasacja-aut.pl到kasacja-aut.pl,然后做一些奇怪的事情。

现在我的网站重定向成这样:https://kasacja-aut.pl/kasacja-aut.pl/kasacja-aut.pl/kasacja-aut.pl/kasacja-aut.pl/kasacja-aut.pl/.再来一遍!

代码语言:javascript
复制
server {
listen 80;
listen [::]:80;
server_name  www.kasacja-aut.pl kasacja-aut.pl;
return 301 https://$kasacja-aut.pl$request_uri;


server {
listen 443 ssl http2;
server_name          kasacja-aut.pl;
index index.html bialogard.html gdansk.html goleniow.html karlino.html kolobrzeg.html koszalin.html miedzyzdroje.html police.html stargard.html swinoujscie.html
szczecin.html szczecinek.html;
root   /var/www/kasacja-aut.pl;


sendfile       off;

access_log /var/log/nginx/auto-kasacja.pl/access.log;
error_log  /var/log/nginx/auto-kasacja.pl/error.log;

    client_body_timeout 5s;
    client_header_timeout 5s;

#Bezpieczeństwo
    add_header Strict-Transport-Security max-age=15768000;

    #Zabezpiecz ciastka :]
    proxy_cookie_domain ~(?P([-0-9a-z]+\.)?[-0-9a-z]+\.[a-z]+)$ "$secure_domain; secure";

    # Clickjacking security.
    add_header                      X-Frame-Options SAMEORIGIN;
        add_header                      X-Content-Type-Options nosniff;
        add_header                      X-XSS-Protection "1; mode=block";

ssl_certificate_key /etc/ssl/auto-kasacja.pl/key.key;
ssl_certificate     /etc/ssl/auto-kasacja.pl/cloudflare.crt;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;


ssl_session_cache   shared:SSL:30m;
ssl_session_timeout 30m;

keepalive_timeout   70;

# CLOUDFLARE RESTORE IP
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2c0f:f248::/32;
set_real_ip_from 2a06:98c0::/29;

# use any of the following two
real_ip_header CF-Connecting-IP;
#real_ip_header X-Forwarded-For;

 location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location / {
    root   /var/www/kasacja-aut.pl;
    error_page 500 502 503 504 404 = /index.html;
        # Wywal boty z Layer-7 damm.
        if ($http_user_agent ~* foo|bar) {
            return 403;
        }
    proxy_cookie_path / "/; secure; HttpOnly";
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff2|ttf|otf|eot|woff)$ {
            expires max;
            log_not_found off;
    }

}

EN

回答 1

Server Fault用户

发布于 2018-03-23 20:27:38

有一个明显的错误可以修复:

代码语言:javascript
复制
return 301 https://$kasacja-aut.pl$request_uri;

我不知道那会有什么用,但可能不是好事。你的意思可能是:

代码语言:javascript
复制
return 301 https://kasacja-aut.pl$request_uri;

但是,如果您计划使用HSTS,您应该首先将HTTPS重定向到相同的主机名,然后在一个单独的HTTPS server块中将www重定向到非www (反之亦然)。

代码语言:javascript
复制
return 301 https://$host$request_uri;
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/904312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档