Redirect http request to https

I am trying to configure HTTPS for elasticsearch using nginx as reverse proxy. I need to access localhost:9200 through HTTP request only. So even if the user tries to access http://localhost:9200 ,it should redirect to https://localhost:9200.

here is my nginx.config file,

server {
    listen       80;
    server_name  localhost;
    return 301 https://localhost:9200;
    }

server {
    listen       443 ssl;
    server_name  localhost;

    ssl_certificate      C:/xxxx/cert.pem;
    ssl_certificate_key  C:/xxxx/newkey.pem;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    location / {
    proxy_pass http://localhost:9200; 
    }
}

When i run http://localhost or https://localhost It redirected to elasticsearch page.
but when i run it with port number http://localhost:9200 it does not redirect to HTTPS request.
also https://localhost:9200 says this site cant provide secure connection.

Do i need to change anything in the above config file.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.