Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On an Amazon EC2 instance, we have nginx and Tomcat running. Nginx is proxying all requests to Tomcat on port 8080 running on the same instance.

This worked fine for a day, but then started seeing a lot of upstream timed out (110: Connection timed out) errors in the nginx logs and the site was inaccessible. Now Tomcat is accessible all right at port 8080. So the problem seems to be somewhere between nginx and Tomcat.

This is what nginx.conf looks like,

worker_processes  1;

events {
    worker_connections  1024;

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

    server {
        listen       80;
        rewrite ^/(.*)$1 permanent;

    server {
        listen       80;
        location / {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_read_timeout 120;
            proxy_connect_timeout 120;


Any insights would be helpful.

Update: After restarting the instance, the site has started to work. I have absolutely no idea what the problem was, but I'll monitor it for a while for such problems.

share|improve this question
Did you actually run into the problem again and got it fixed for real? I'm asking since I started to run into the situation you described a couple of times during the last months: nginx <-> upstream connection timeout although the upstream runs fine and fast when queried directly. A reload of the nginx workers then makes the problem disappear... – severin May 29 '13 at 12:21
as far as i can remember, i didn't run into this problem after. A few months later, I moved out of the project and have no idea since. You may want to try Fleshgrinder's solution below and monitor it for a while. As it stands, I really don't know what the real problem was nor the real solution :) Best wishes. – aldrin May 30 '13 at 5:25
Thanks for your response! – severin May 30 '13 at 8:19

Please use the following for redirecting:

server {
    listen       80;
    return 301 $scheme://www.$server_name$request_uri;

Add the following to your configuration:

error_log /var/log/nginx/error.log debug;

And evaluate, or post the result here.

share|improve this answer
the site started working after a restart, without any config changes. is there a reason for preferring a 'return' instead of a 'rewrite' ? – aldrin Aug 19 '12 at 4:06
WAY FASTER! There is no regular expression to parse and compile each time a request comes in. – Fleshgrinder Aug 19 '12 at 13:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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