Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I currently have an nginx server which can be accessed by typing in domain.com both by HTTP and HTTPS. However when I attempt to connect by typing www.domain.com instead it seems that the connection will hang and Firefox reports "The connection to the server was reset while the page was loading.."

Here is my current server_name config:

server_name localhost www.example.com example.com;

The nginx documentation seems to suggest that this should work, what am I doing wrong?

share|improve this question
1  
Do those two domains both resolve to the same IP address? –  Ladadadada Mar 2 '13 at 22:12

1 Answer 1

This

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

will redirect example.com to www.example.com, and this

server {
    listen  80;
    server_name www.example.com;

    location / {
        root   /var/www/example.com;
        index  index.html index.htm;
        }
    }

will serve www.example.com.

You can do the same for https but it's unlikely that anyone will laboriously enter https:// and the non-cannonical address, so

server {
    listen  443;
    server_name www.example.com;


    ssl  on;
    ssl_certificate  /etc/ssl/private/www.example.com.crt;
    ssl_certificate_key /etc/ssl/private/www.example.com.key;

    ssl_session_timeout  10m;
    ssl_session_cache shared:SSL:10m;

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


    location / {
        root   /var/www/example.com;
        index  index.html index.htm;
        }
    }

should suffice.

share|improve this answer
2  
Please don't place root inside location /. This is a very common nginx misconfiguration. –  Michael Hampton Mar 2 '13 at 23:34

Your Answer

 
discard

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.