search

Home  >  Q&A  >  body text

hosts - Using nginx to configure virtual host under ubuntu fails

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.

PHP中文网PHP中文网2696 days ago1367

reply all(3)I'll reply

  • 代言

    代言2017-07-06 10:39:31

    Suppose the configuration file you added in the /etc/nginx/site-avaliable/ directory is called test.com.conf

    Note, 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 to site-enabled/)

    Restart the Apache service sudo service apache2 restart

    It should be fine

    reply
    0
  • Frank

    very good

    Frank · 2020-10-29 13:12:17
  • 世界只因有你

    世界只因有你2017-07-06 10:39:31

    I found a better article, suitable for ubuntu16.04 + nginx environment.
    https://www.digitalocean.com/...

    reply
    0
  • Cancelreply