Environment: ubuntu16.04 nginx1.10.0
nginx configuration file /etc/nginx/site-available/default
hosts file location /etc/hosts
1. This machine has been configured with a virtual host localhost, and the root directory is mapped to /var/www/localhost
2. I want to add a virtual host, so add a test.com virtual host configuration file in the /etc/nginx/site-avaliable/ directory. The root directory is mapped to /var/www/test.com, and in hosts Add 192.168.1.104 test.com (local IP) to the file, but after restarting the nginx service, accessing test.com is still the same as accessing localhost. How to solve it? Thanks.
Suppose the configuration file you added in the
/etc/nginx/site-avaliable/
directory is called test.com.confNote, it must end with .conf, nothing else will work.
Then inside ssh, enter
sudo a2ensite test.com.conf
(This sentence essentially tells you to create a shortcut to
site-avaliable/test.com.conf
tosite-enabled/
)Restart the Apache service
sudo service apache2 restart
It should be fine
I found a better article, suitable for ubuntu16.04 + nginx environment.
https://www.digitalocean.com/...