I am running Ubuntu 14.04.3 and Nginx 1.4.6 on Amazon EC2. I'm trying to set up a reverse proxy for my application on port 8000, which I can see running when I go to www.mywebsite.com:8000. The reverse proxy should redirect all http traffic to https, and then serve the application.

Here is my sites-enabled config:

server {
  listen 80;
  server_name mywebsite.com
  return 301 https://$host$request_uri;

server {
  listen 443 ssl;
  server_name mywebsite.com

  access_log  /var/log/nginx/access.log;
  error_log   /var/log/nginx/error.log;

  ssl on;
  ssl_certificate     /etc/nginx/ssl/certificate.crt;
  ssl_certificate_key /etc/nginx/ssl/key.key;
  keepalive_timeout   60;

  ssl_ciphers             HIGH:!ADH:!MD5;
  ssl_protocols           TLSv1;
  ssl_prefer_server_ciphers on;

  proxy_buffers 16 64k;
  proxy_buffer_size 128k;

location / {
    proxy_pass  http://IPADDRESS:8000;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_redirect off;
    proxy_read_timeout 60m;

    proxy_set_header    Host            $host;
    proxy_set_header    X-Real-IP       $remote_addr;
    proxy_set_header    X-Forwarded-Host $http_host;
    proxy_set_header    X-Forwarded-Server $host;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto https;
    proxy_set_header    Front-End-Https On;

At first I used localhost as my IPAddress, but after reading this question which suggests using ec2's private IP, not the public, I tried that too. But no cigar.

I have a terminal open which is ssh'd into my application, so I can see when a http request comes in, which it did when I visited mywebsite.com:8000. However www.mywebsite.com is a blank page that eventually gets a time out, and my application shows it didn't receive the initial request. Nginx is the only application listening on port 80 & 443.

My Error and access logs are also empty. Can anybody see whats going on?


Nginx was listening on port 80 however a cURL attempt returned with connection refused, it turns out my iptables defaults had been changed. Flushing these back to default allowed traffic to hit Nginx.

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT

Interestingly using Ec2's private IP address when proxying wasn't necessary as localhost worked fine.

  • 1
    If the logs are empty, then you're not actually hitting nginx. The problem is upstream of that point. – womble Sep 22 '15 at 8:14
  • Thanks for the quick answer. I'll post an update and hopefully an answer for references. – BJacks Sep 22 '15 at 8:31

Your Answer

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

Browse other questions tagged or ask your own question.