hosts - Using nginx to configure virtual host under ubuntu fails
PHP中文网
PHP中文网 2017-07-06 10:37:31
0
3
1378

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中文网

认证0级讲师

reply all(2)
代言

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 very good
    Frank author 2020-10-29 13:12:17
世界只因有你

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template