robert williams robert williams - 2 months ago 16
Apache Configuration Question

forwarding all requests from one port to another nginix

can i please know how to forward all the requests coming from port 80 to 443?
my code:

server {
listen 80;

root /var/www/html/;
index index.html index.htm index.php;
server_name myexample.com;

location / {

proxy_pass http://myexample.com:443/;

}
}

server {

listen 443;

root /var/www/html/;
index index.html index.html index.php;
server_name myexample.com;
}


but requests to http://myexample.com are not redirecting to https://myexample.com

Answer

Redirect HTTP to HTTPS

server {
    listen 80;        
    server_name myexample.com;
    return  301 https://$host$request_uri;
}

server {
    listen 443;
    root /var/www/html/;
    index index.html index.html index.php;
    server_name myexample.com;
}