Question

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

  • Posted August 2, 2013

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;
} }

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Sweet, glad you figured it out :] It usually says it in the error logs which are found in /var/log.

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. <br> <br>That line was commented out by default so I uncommented and restarted nginx and it works fine now.