LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   CentOS (https://www.linuxquestions.org/questions/centos-111/)
-   -   apache VirtualHost not accessible from outside (https://www.linuxquestions.org/questions/centos-111/apache-virtualhost-not-accessible-from-outside-4175611475/)

Sefid par 08-07-2017 08:37 AM

apache VirtualHost not accessible from outside
 
I have two questions.
I'm trying to create a VirtualHost on VPS with CentOS 7.
I've created a file eset.lo.conf in sites-available:
Code:

'/etc/httpd/sites-available/eset.lo.conf'
and linked to it in
Code:

'/etc/httpd/sites-enabled/eset.lo.conf'.
Also added the line
Code:

IncludeOptional sites-enabled/*.conf
to httpd.conf
and added the hostnames in /etc/hosts:
Code:

<IP> eset.lo www.eset.lo
the eset.lo.conf is like this:
Code:

<VirtualHost *:80>
        ServerName eset.lo
        ServerAlias eset.lo *.eset.lo
        DocumentRoot "/var/www/html/eset"
        <Directory /var/www/html/eset/>
                AllowOverride All
                Options All
                #Order allow,deny
                Allow from all
                Require all granted
        </Directory>
</VirtualHost>

also added the index.html in /var/www/html/eset with content:
Code:

"Hello, Here is html/eset"
Now, This site is available in VPS itself when I do curl:
Code:

curl http://eset.lo/
output:
Hello, Here is html/eset

Ok.
When I also do 'curl http://localhost/'
I get the same output: Hello, Here is html/eset

And the next question is:
I want to access this VHost from my personal computer. I've added it's IP to my /etc/hosts:
Code:

<IP> est.lo www.est.lo
But it's not accessible. The 'curl -v http://eset.lo/' is:
Code:

curl -v http://eset.lo/
*  Trying <IP>...
* TCP_NODELAY set
* Connected to eset.lo (<IP>) port 80 (#0)
> GET / HTTP/1.1
> Host: eset.lo
> User-Agent: curl/7.54.1
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

and when I open the IP of VPS, I get the same output again:
Hello, Here is html/eset.

What's wrong with my configuration?
And why localhost inherited VirtualHost configuration?

bathory 08-07-2017 10:54 AM

Quote:

Ok.
When I also do 'curl http://localhost/'
I get the same output: Hello, Here is html/eset

And the next question is:
<snip>
and when I open the IP of VPS, I get the same output again:
Hello, Here is html/eset.

What's wrong with my configuration?
And why localhost inherited VirtualHost configuration?
For both your questions:
If you have defined only one vhost, then that's also the default one, so vising your webserver either as localhost, or by its IP, you will get the default vhost, that in your case is eset.lo

Sefid par 08-07-2017 11:00 AM

Thanks a lot. But, When I call "eset.lo" from my computer, Although I've binded the host and IP in /etc/hosts, Why I don't get access to the VHost? It's output is nothing as I shown in 'curl':
Quote:

Originally Posted by Sefid par (Post 5745448)
Code:

curl -v http://eset.lo/
*  Trying <IP>...
* TCP_NODELAY set
* Connected to eset.lo (<IP>) port 80 (#0)
> GET / HTTP/1.1
> Host: eset.lo
> User-Agent: curl/7.54.1
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer



bathory 08-07-2017 11:34 AM

Quote:

Thanks a lot. But, When I call "eset.lo" from my computer, Although I've binded the host and IP in /etc/hosts, Why I don't get access to the VHost? It's output is nothing as I shown in 'curl':
As you noted in your OP, the problem goes away when you "open" the IP in VPS. So I guess it's a firewall problem.
Quote:

and when I open the IP of VPS, I get the same output again:
Hello, Here is html/eset.

Sefid par 08-07-2017 12:41 PM

Excuse me. I told badly. I meant when I open IP using browser. I've set the firewall rule before configure the VHost, And port 80 was open when the problem occurred.

bathory 08-07-2017 01:40 PM

Quote:

Originally Posted by Sefid par (Post 5745549)
Excuse me. I told badly. I meant when I open IP using browser. I've set the firewall rule before configure the VHost, And port 80 was open when the problem occurred.

Anyway, it's a networking problem, not an apache one.

nejnej25 12-29-2017 12:29 AM

You need to buy the domain name you want for your VPS. In your example is www.eset.lo so the DNS server can reach your VPS thru a domain name.

domain name mapping inside /etc/hosts is good for local use and pings.


All times are GMT -5. The time now is 08:05 AM.