I have multiple local sites and I want to configure nginx to have a different host of each website.
In /var/www I have 2 sites: site1 and site2
Then in /etc/nginx/sites-available/ I created 2 different configurations server for each one. I have the files site1 and site2 which content is like:
server {
listen 80;
root /var/www/site1;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
}
and
server {
listen 7777;
root /var/www/site2;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
}
I access to them with http://localhost:80 for site1 and http://localhost:7777 for site2. That works perfectly. I also could add the hostname in /etc/hosts like this:
127.0.0.1 localhost site1 site2
and I could access them with http://site1:80 and http://site2:7777. But I have to access always to the port number. I want to access them by http://site1 and http://site2.
Is there a solution to do that ?