Home Top Ad

Host Multiple Domains on One Server/IP with nginx

Share:





Prerequisites





Before you get started with this guide, you need to have some basic steps completed.





We’re also going to assume that you’ve completed a LEMP (Linux, NGINX, MySQL, and PHP) installation on your Ubuntu 18.04 server. If this is not completed yet, you can follow this guide on installing a LAMP stack on Ubuntu 18.04.





We’re also going to assume that you’ve completed a phpmyadmin installing on LEMP





For these reasons, and because it is a widely-deployed PHP application which is frequently targeted for attack, you should never run phpMyAdmin on remote systems over a plain HTTP connection. If you do not have an existing domain configured with an SSL/TLS certificate





Once you are finished with these steps, you’re ready to get started with this guide.





Host Multiple Domains on One Server





sudo mkdir -p /var/www/html/SITE1
sudo mkdir -p /var/www/html/ SITE 2





sudo chown -R $USER:$USER /var/www/html/ SITE 1
sudo chown -R $USER:$USER /var/www/html/ SITE 2





sudo chmod -R 755 /var/www/html/ SITE 1
sudo chmod -R 755 /var/www/html/ SITE 2





sudo nano /etc/nginx/sites-available/ SITE 1.conf





server {
listen 80;
root /var/www/html/ SITE 1;
index index.php index.html index.htm index.nginx-debian.html;
server_name SITE1;





    location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
deny all;
}




}





sudo nano /etc/nginx/sites-available/SITE2.conf





server {
listen 80;
root /var/www/html/SITE2;
index index.php index.html index.htm index.nginx-debian.html;
server_name SITE2;





    location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
deny all;
}




}





sudo ln -s /etc/nginx/sites-available/SITE1.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/SITE2.conf /etc/nginx/sites-enabled/





chown www-data:www-data /var/www/html/SITE1
chown www-data:www-data /var/www/html/SITE2





sudo nginx -s reload
sudo nginx -t
systemctl reload nginx





Congratulation same method you can host multible website in one serve