Nginx 301 jumps to the link with,

visit https://www.oyohyee.com/admin]
will be redirected to [ http://www.oyohyee.com,www.oy.]
use curl-IL https://www.oyohyee.com/admin
to get the following information

HTTP/1.1 301 MOVED PERMANENTLY
Server: nginx/1.12.2
Date: Thu, 12 Apr 2018 00:45:21 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 297
Connection: keep-alive
Location: http://www.oyohyee.com,www.oyohyee.com/admin/

(here is the jump made by nginx, and the link after the jump is http protocol)

preliminary judgment is nginx"s problem, but I don"t know how to solve it, and I wonder why there is this jump

I want to be able to jump to [ https://www.oyohyee.com/admin/]

according to the flask rules. < hr >

related information is as follows:

centos + nginx + gunicorn + flask

flask routing function

server {
    listen       80;
    server_name www.oyohyee.com;
    rewrite ^(.*)$  https://$host$1 permanent;
}

server {
    listen       443 ssl http2 default_server;
    server_name www.oyohyee.com;

    ssl_certificate "/etc/nginx/ssl/1_www.oyohyee.com_bundle.crt";
    ssl_certificate_key "/etc/nginx/ssl/2_www.oyohyee.com.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    location ^~ / {
        proxy_pass              http://127.0.0.1:8000/;
        proxy_redirect          off;
        proxy_set_header        Host $host;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-Host $server_name;
        proxy_set_header        Host $http_host;
    }

    location ^~ /static/ {
         root  /data/OBlog/OBlog/front/;
    }
}
Mar.02,2021

The reason why the domain name of Location of

301 jump duplicates and has an extra comma is that the Host header

is added when nginx is reversed.
        proxy_set_header        Host $host;
        proxy_set_header        Host $http_host;

remove the bottom

< hr >

2. In addition, you have to let the Python code know that the protocol is https

1) try adding these two headers to nginx

proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;

2) if it is not valid, you need to adjust the code and read the X_Forwarded_Proto header of the request to get the protocol
reference code:

from flask import Flask
from werkzeug.contrib.fixers import ProxyFix

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35b25-2b730.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35b25-2b730.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?