0

I had successfully got the cert of my SSL and now I was trying to implement it into my AWS server with NGINX reserve proxy setup, here is the config file:

server {
    listen       80;
    server_name  example.com;
    return       301 https://www.example.com$request_uri;
}

server {
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/cert_chain.crt;
    ssl_certificate_key /etc/nginx/ssl/website.key;
    server_name ~^(?<subdomain>.+)\.example\.com$;

    location / {
        proxy_pass http://www.example.com:8888;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $subdomain.example.com;
        proxy_cache_bypass $http_upgrade;
    }
}

If I change the setting to listen to port 80 then it's working fine. I had enabled port 443 in AWS security group and here is the result of netstat -tulpn | grep 443:

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      -

So it means it's listening to port 443 already right? I also ensured that the nginx was run as root using ps aux|grep nginx|grep -v grep:

root     11567  0.0  0.3 177080  3060 ?        Ss   09:36   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 11568  0.0  0.7 177344  7568 ?        S    09:36   0:00 nginx: worker process

I had checked the Nginx error log and it got nothing inside, but when I access my url with https it just showing that it took too long to respond. Anyone able to help? Thank you.

3
  • Did you open the port on all the firewalls between your server and the internet to allow port 443? I see you done the security group, but what about on the server itself
    – Drifter104
    Aug 8 '17 at 11:31
  • @Drifter104 yes I had checked my server and there is no firewall activated.
    – Ping
    Aug 8 '17 at 13:05
  • Maybe you should check with something like tcpdump just to be sure that https traffic is coming all the way to your server: tcpdump -n dst port 443. Put tcpdumpdump listening and try your domain from browser and see if any traffic is showing in tcpdump. You can also check with netcat on server that connecting to port 443 works nc -vv localhost 443. Also check that if you have symlink between sites-enabled/your.site and sites-available/your.site that it is working properly and all your changes are visible under sites-enabled.
    – MKT
    Aug 9 '17 at 16:53
-2

replace your first server section with

server {
        listen 80;
        server_name  example.com;
        location / {
        rewrite ^/(.+) https://example.com/ permanent;
        }
       }
1
  • I don't think is there any issue with this line, it's just for redirection when accessing without www, I was accessing the url with www all the time.
    – Ping
    Aug 8 '17 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.