简体   繁体   中英

How can I redirect traffic from Port 80 to Port 443 using UFW?

I use Ubuntu Server 18.04 and wish to forward/redirect traffic from port 80 to port 443 ( https ).

I want to do this as I have SSL on NGINX(port 80) and a Flask app running on Gunicorn on port 443. I can't make NGINX proxy requests as the app isn't in a virtualenv .

I wish to use UFW. How can I do this?

Redirecting http to https traffic is not the purpose of a firewall like ufw .

You should redirect the requests within NGINX as follows:

server {
    listen 80;

    server_name example.org;
    return 301 https://example.org$request_uri;
}

... where 80 is the http port, example.org is your domain, and 301 indicates the browser that the resource is accessible at the other place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM