I have multiple services running on my server which will be accessed via nginx and encrypted by certbot.
If i want to acess my service with my http://example.com
, I get redirected to http(s)://example.com
, which is great.
However, if I type in my IpAdress:Port
I wont get redirected to my domain.
This is my abc.com file in /etc/nginx/sites-enabled
server {
server_name abc.com; #example: mysite.xyz
#access_log /var/log/nginx/<servicename>.access.log;
#error_log /var/log/nginx/<servicename>.error.log;
location / {
proxy_pass http://127.0.0.1:9000; # here you define the address, which is used by nginx to access your service
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
} # this is the port you use to access the proxied service
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/abc.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/abc.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = abc.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name abc.com;
listen 80;
return 404; # managed by Certbot
}
Can someone tell me or point me into a direction what I need to change in my abc.com file in order to redirect also requests via IpAdress:Port
to https://example.com
I am grateful for any help!
Edit:
I have made my services reachable via localhost which solved my problem. Thank you all for your contributions!