Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Vishnu-m-r/63b2dc2f2a916f2cb5219b329d266bc1 to your computer and use it in GitHub Desktop.
Save Vishnu-m-r/63b2dc2f2a916f2cb5219b329d266bc1 to your computer and use it in GitHub Desktop.
Nginx - Configure multiple domains to point to same server with multiple websites Ubuntu 16.04
##Configure both domains to point to same ip
Nginx Configuration
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com</a>
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/test.com</a>
example.com
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /root/to/index.html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name example.com www.example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
test.com
server {
listen 80;
listen [::]:80;
root /root/to/index.html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name teachedison.co.in www.teachedison.co.in;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment