steroyle
By:
steroyle

How do I setup separate config files for different sites on nginx

August 2, 2013 4.8k views
I have 2 sites and I want to create a separate config files for each, I have created the 2 configs and a symlink for each. The problem is both domains show the same page rather than going to their own separate pages: *** Config 1 *** server { listen 80; server_name www.domain1.co.uk; root /var/www/domain1.co.uk; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.html; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/domain1.co.uk; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } *** Config 2 *** server { listen 80; server_name www.domain2.co.uk; root /var/www/domain2.co.uk; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.html; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/domain2.co.uk; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
2 Answers
I've fixed this now, in case anyone has the same problem as me it was to do with "server_names_hash_bucket_size 64;" in /etc/nginx/nginx.conf.

That line was commented out by default so I uncommented and restarted nginx and it works fine now.
Sweet, glad you figured it out :] It usually says it in the error logs which are found in /var/log.
Have another answer? Share your knowledge.