taken from here
sudo apt-get install nginx
The first step in creating a virtual host is to a create a directory where we will keep the new website’s information.
mkdir ~/nginx_html
We need to create a new file called index.html within the directory we made earlier.
vi nginx_html/index.html
We can add some text to the file so we will have something to look
<h1>Success: You Have Set Up a Virtual Host</h1>
create an nginx config file:
sudo vi /etc/nginx/sites-available/nginx_html
add these few lines:
server {
listen 4000; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /home/<user>/nginx_html;
index index.html index.htm;
# Make site accessible from http://localhost/
# server_name localhost;
}
Activate the host by create a symbolic link between the sites-available
directory and the sites-enabled
directory (in apache, the command to accomplish this is a2ensite
, but nginx does not have an equivalent shortcut):
sudo ln -s /etc/nginx/sites-available/nginx_html /etc/nginx/sites-enabled/nginx_html
We’ve made a lot of the changes to the configuration. Restart nginx and make the changes visible.
sudo service nginx restart
Visit http://localhost:4000 in your browser