【问题标题】:How to disable redirection of http to https (Nginx, CertBot)如何禁用 http 到 https 的重定向(Nginx、CertBot)
【发布时间】:2021-06-27 10:43:06
【问题描述】:

我试图不将 http 重定向到 https....

我试图研究但发现什么都没有...

顺便说一句,我执行了这两个命令来创建新文件,而不是在启用的网站上使用默认文件:

sudo touch /etc/nginx/sites-available/imallbd
sudo nano /etc/nginx/sites-available/imallbd

然后:

sudo ln -s /etc/nginx/sites-available/imallbd /etc/nginx/sites-enabled/imallbd

这是我的网站启用文件

server {

    server_name imallbd.com;

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

    index index.html index.htm index.php;

    charset utf-8;

    # For API
    location /api {
        alias /var/www/imallbd/api/public;
        try_files $uri $uri/ @api;
            location ~ \.php$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
         }
    }

    location @api {
      rewrite /api/(.*)$ /api/index.php?/$1 last;
    }

    # For FrontEnd -> GraphQL
    location /{
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /admin{
        proxy_pass http://localhost:3000/admin;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

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

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/imallbd.com/fullchain.pem; # managed >
    ssl_certificate_key /etc/letsencrypt/live/imallbd.com/privkey.pem; # manage>
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot




}
server {
    if ($host = imallbd.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;

    server_name imallbd.com;
    return 404; # managed by Certbot


}

请帮忙!!!顺便说一句,当我访问我的网站时,它给了我 502 bad gateway ......这不是我要问的问题,但如果你能给我一些帮助提示或答案,我将非常感激 :)

当我跑步时:

sudo nginx -t

   nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
   nginx: configuration file /etc/nginx/nginx.conf test is successful

如果您想了解更多我可以提供的详细信息或信息,请在 cmets 上告诉我!

提前致谢!!!

【问题讨论】:

    标签: http nginx web https server


    【解决方案1】:

    首先为什么要移除 https 重定向?

    无论哪种方式,您都可以删除这部分:

    if ($host = imallbd.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    

    这将删除 http -> https 重定向。

    另外,如果您在 nginx 中进行任何更改,您需要重新启动 te 服务。 假设您使用的是基于 linux 的操作系统运行:

    systemctl restart nginx
    

    你的nginx的502报错问题是和php有关的。

    php 进程没有运行,已经崩溃或者 nginx 无法与之通信。

    你有什么样的 php 安装? php-fpm ?如果是这样的话,运行

    systemctl restart php-fpm
    

    如果没有。在 cmets 中告诉我(在 cmets 中没有足够的代表说这个)

    【讨论】:

    • 我不想重定向到 https,因为它给了我错误,因为我的链接是 http,而且,是的,我正在使用 php-fpm。感谢您发布答案,我现在就试试
    • 嗨 xAtifx 我明白了。这就是为什么你需要删除:``` if ($host = imallbd.com) { return 301 https://$host$request_uri; } # 由 Certbot 管理 ``` 301 是永久移动的状态码。这会将所有内容从端口 80(又名 http)重定向到 https://$host Zo,如果您删除它不会再重定向到 https
    • 我自己已经修好了,但你的一些回答帮助了我,所以享受投票和检查:)
    猜你喜欢
    • 2015-07-16
    • 2020-01-11
    • 2021-03-02
    • 2022-08-14
    • 2011-03-29
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多