Nginx Multiple Domains
Posted
by
showFocus
on Server Fault
See other posts from Server Fault
or by showFocus
Published on 2011-04-28T02:20:34Z
Indexed on
2012/04/14
11:33 UTC
Read the original article
Hit count: 253
I am trying to add a second virtual host to nginx. When i go to the new domain it redirects to the old one. I have tried restarting Nginx, rebooting the server.
Has anyone come across this before, care to share?
File: nginx.conf ###
user www-data www-data;
worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 5;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /usr/local/nginx/sites-enabled/*;
}
File: ../sites-enabled/domain1.co.uk
server {
listen 80;
server_name www.domain1.co.uk;
rewrite ^/(.*) http://domain1.co.uk/$1 permanent;
}
server {
listen 80;
server_name domain1.co.uk;
access_log /home/me/public_html/domain1.co.uk/log/access.log;
error_log /home/me/public_html/domain1.co.uk/log/error.log;
location / {
root /home/me/public_html/domain1.co.uk/public/;
index index.php index.html;
# WordPress supercache & permalinks.
include /usr/local/nginx/conf/wordpress_params.super_cache;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/me/public_html/domain1.co.uk/public/$fastcgi_script_name;
}
}
File: ../sites-enabled/domain2.co.uk
server {
listen 80;
server_name www.domain2.co.uk;
rewrite ^/(.*) http://domain2.co.uk/$1 permanent;
}
server {
listen 80;
server_name domain2.co.uk;
access_log /home/me/public_html/domain2.co.uk/log/access.log;
error_log /home/me/public_html/domain2.co.uk/log/error.log;
location /
{
root /home/me/public_html/domain2.co.uk/public/;
index index.php index.html;
# Basic version of WordPress parameters, supporting nice permalinks.
# include /usr/local/nginx/conf/wordpress_params.regular;
# Advanced version of WordPress parameters supporting nice permalinks and WP Super Cache plugin
include /usr/local/nginx/conf/wordpress_params.super_cache;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/me/public_html/domain2/public/$fastcgi_script_name;
}
}
© Server Fault or respective owner