0

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 :

  1. Application URL that serves in 7000 port is "http://example.com:7000/#/
  2. Port 80 was already taken for another application
  3. Currently I have a wild card SSL certificate
  4. The server IP was pointed only to a single domain only
0

2 Answers 2

0

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

2
  • Thank you...!!! Finally, it was worked for me Commented Sep 18, 2020 at 15:11
  • @aravindks No worries. If you would mark it as the answer the I would appreciate it ;) Commented Sep 18, 2020 at 19:54
1

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?

1
  • Thank you so much for your reply. If I am using two ports how do I need to change the above Nginx rule? Means if am using two ports 7000 and 6000. How do I rewrite to change the above config file Commented Sep 18, 2020 at 5:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.