I have deployed my front end application in 7000 ports. So I need to write a rule in Nginx so that whenever all the HTTP request from 7000 ( HTTP://example.com:7000) port will automatically redirect HTTPS in the same port(HTTPS://example.com:7000)
Please support me to solve the issue. This is my current Nginx configuration file
server {
listen 7000 ssl;
ssl_certificate /new_keys/new_k/ssl_certificate/star_file.crt;
ssl_certificate_key /new_keys/new_k/ssl_certificate/private.key;
root /home_directory;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /custom_404.html;
location = /custom_404.html {
root /usr/share/nginx/html;
internal;
}
}
Note :
- Application URL that serves in 7000 port is "http://example.com:7000/#/
- Port 80 was already taken for another application
- Currently I have a wild card SSL certificate
- The server IP was pointed only to a single domain only
You can't listen for both HTTP and HTTPS at the same time with NGINX, you need two separate ports.
Why's the fact that an application is already running on port 80 preventing you from adding another domain?
Try using a custom error page for error code 497. This error is raised by nginx, when https websites are accessed via http. Just add:
error_page 497 https://$host:$server_port$request_uri;
to your configuration and it should exactly do what you defined as the requirement in your question.
Lookup below discussion for more information: Handling http and https requests using a single port with nginx