Question

Nginx redirect me to a real site web not my virtual site

Posted March 18, 2021 222 views
Nginx

Hi , it te first time that i use nginx ! so i’m asking why if i add a virtual domain name in /etc/host for exemple
192.168.2.1 exemple.com www.exemple.com
and i follow this tuto https://vexxhost.com/resources/tutorials/how-to-set-up-nginx-virtual-hosts-on-ubuntu/ but it doesn’t work :(
cna someone help me ??

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hi,

If you had opened exemple.com in your web browser before you modified your /etc/hosts file, then it is very likely that your web browser cached exemple.com site’s content and respond with such cache content to each next request sent to exemple.com. What I can suggest is to clear browser’s cache and try again then.

Let us know if it helps.

Hi yannek !!
no a did not open the browser before !! and it’s the same think …
even when i test a domaine name inexsisted for exemple lalalili.com it doesn’t work :(

  • Some tips:

    1. Check if you have not misspelled hosts file name, and what rights are set up for /etc/hosts file. Run the command:

    sudo ls -la /etc/host*
    

    You will get the result like below. The hosts file is highlighted. Everyone should have right to read this file.

    Output
    -rw-r--r--. 1 root root 9 Jun 7 2013 /etc/host.conf -rw-r--r--. 1 root root 22 Apr 10 2017 /etc/hostname -rw-r--r--. 1 root root 158 Mar 18 23:23 /etc/hosts -rw-r--r--. 1 root root 370 Jun 7 2013 /etc/hosts.allow -rw-r--r--. 1 root root 460 Jun 7 2013 /etc/hosts.deny

    2. To check quickly if changes in hosts file work, you can ping the host you entered in hosts file, e.g. in my case:

     ping lalalili.com
    

    I get the result like that:

    Output
    PING lalalili.com (10.10.10.10) 56(84) bytes of data.

    because my hosts file looks like that:

    /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    10.10.10.10  lalalili.com www.lalalili.com
    

    Try to ping a host you entered into your hosts file and let us know how it works.

    BTW. Domain lalalili.com exists ;-)
    https://www.whois.com/whois/lalalili.com