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
aks
  • 37
  • 1
  • 6

2 Answers2

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?

Ginnungagap
  • 1,998
  • 8
  • 9
  • 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 – aks Sep 18 '20 at 05:41
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

Lorem ipsum
  • 852
  • 3
  • 13