2

Below is my NGINX configuration. My website is deployed on AWS EC2 instance. I have checked the firewall settings and port 443 is open for public access.

I'm able to access my website from http://example.com. But I'm unable to access the website from https://example.com.

If I change the setting from listen 443; to listen 443 ssl;. I'm getting an error while restarting the NGINX service.

I have secured SSL certificate from AWS Certificate Manager.

Config file:

server {
    listen 80;
    listen [::]:80;

    listen 443;

    # listen 443 ssl; 


    root /opt/bitnami/apps/my_website;
    index index.html;

    server_name example.com www.example.com;

    location / {
            try_files $uri $uri/ =404;
    }
}

Edit:

nginx version: nginx/1.16.1

I tried the command sudo nginx -t

Response:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Edit 2: Adding some more details: The config file mentioned previously is located at /etc/nginx/sites-available/example.com

Here is the code for nginx.conf file located at /etc/nginx/nginx.conf

 user  nginx;
 worker_processes  1;

 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;


 events {
worker_connections  1024;
 }


http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

#gzip  on;

 include /etc/nginx/conf.d/*.conf;

 include /etc/nginx/sites-enabled/*;

# include /etc/nginx/sites-enabled/*.*;
#include /etc/nginx/sites-available/*;

}

Code for conf.d located at /etc/nginx/conf.d

../
./
default.conf                                                                                                                                                                                
Anirudh
  • 119
  • 5

1 Answers1

0

1) Check listeners are currently configured in load balancer and proper SSL Certificate is assigned to HTTPS Protocol in "Listner tab".

2) Check Loadbalancer Security group.

3) Check EC2 Instance Security group.


server {

listen 80;

server_name www.example.com;

root /path/to/web/dir;

index index.html index.htm;

proxy_set_header X-Forwarded-Proto $scheme;

if ( $http_x_forwarded_proto != 'https' ) {

return 301 https://$host$request_uri;

}

}

Sreeraju V
  • 381
  • 3
  • 16