How To Set Up nginx Virtual Hosts
1) Install the following pagkage
sudo apt-get install nginx
2) Create New Directory and grant permissions
sudo mkdir -p /var/www/example.com/public_html
sudo chown -R www-data:www-data /var/www/example.com/public_html
sudo chmod 755 /var/www
3) create an index page
sudo nano /var/www/example.com/public_html/index.html
<html> <head> <title>www.xyz.com</title> </head> <body> <h1>Test Page</h1> </body> </html>
4) Create virtual host
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/xyz.com
sudo nano /etc/nginx/sites-available/xyz.com
5 ) We need to make a couple of changes in these few lines:
server { listen 80; root /var/www/xyz.com/public_html; index index.html index.htm; server_name xyz.com; }
- sudo ln -s /etc/nginx/sites-available/xyz.com /etc/nginx/sites-enabled/xyz.comsudo
6) Restart the service
sudo service nginx restart
7) create host lookup
vim /etc/hosts
#Virtual Hosts x.x.x.x www.xyz.com
No comments:
Post a Comment