I’m using an asp.net core app that calls the function app.UseHttpsRedirection();
and app.UseHsts();
.
I can host the app on ubunto server on port 5000 for http and 5001 for https.
Now I need to host this with ngnix. This is my config:
server {
listen [::]:443 ssl default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name myServername;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
}
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-Proto $scheme;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
Now when I call my page, it forwards me to https://myServername:5001
. I need to change this port to be the standard port of https 443.
How should it be done?
Please note, that I have added my certificate there in the asp.net application.
2
Answers
I could solve it. My mistakes were:
app.UseHttpsRedirection();
from the code.Following link is helpful: https://github.com/tonysneed/Demo.AspNetCore-Nginx-Ssl
I was pointing to plain http
localhost:5000
with nginx, as always, then was using certbot to secure connection. I have no idea why, but propably after .Net update it started to redirect from my domain to***.5001
and of course throws error.App was working with same settings for 1 year, and had no problem. I have checked it also in git history, there was
app.UseHttpsRedirection();
.I rolled back, checked, it started working, and ran dotnet update last night again, and it caused problem of
307
redirect.I have no idea why two versions of .Net works different but
/*app.UseHttpsRedirection();*/
did the trick.