Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VirtualHost setup always doesn't work

I'm trying to set up a virtualHost for mampstack (NOT MAMP). This is what I've done so far:

In my httpd.conf file I've checked

Listen 8080

This is correct (I'm listening to the port 8080, NOT 80).
Then I've uncommented: Include conf/extra/httpd-vhosts.conf in my httpd.conf file
In my hosts file I have added the following: 127.0.0.1 mext-pst.local.

In httpd-vhosts.conf I've added:

NameVirtualHost *:8080
<VirtualHost *:8080> 
    DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs"
    ServerName                127.0.0.1
    ServerAlias               localhost
    SetEnv APPLICATION_ENV    development
    SetEnv APPLICATION_DOMAIN localhost
</VirtualHost>

<VirtualHost *:8080> 
    DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/mext-pst-dashboard/web"
    ServerName mext-pst.local
    ServerAlias mext-pst.local
    SetEnv APPLICATION_ENV    development
    SetEnv APPLICATION_DOMAIN mext-pst.local
    RewriteEngine on
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]
</VirtualHost>

Now when I go to http://mext-pst.local/ I just get an error of my browser that he can't connect with the page ... .
When I go to http://mext-pst.local:8080/ I get the following error:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /index.php.

Reason: DNS lookup failure for: mext-pst.local:8080

When I go to http://mext-pst.local:8080/index.php it works ...

like image 781
nielsv Avatar asked Oct 02 '22 13:10

nielsv


2 Answers

Change 8080 to 80 its the default. But if you want your site to run on 8080, then you have to use it. Another solution might be to rewrite the url, that is when your server gets the url, it rewrites it with port number (8080).

First of all change Listen 8080 to Listen 80, as you want your application to be accessible only with http. In your http-vhost.conf file put following lines (of course after removing previous changes). In the following configuration yourDefaultHttpFolder means the default http folder. You might have changed it. So correct it depending on your system.

<VirtualHost *:80> 
   DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/yourDefaultHttpFolder"
   ServerName                127.0.0.1
   ServerAlias               localhost
   SetEnv APPLICATION_ENV    development
   SetEnv APPLICATION_DOMAIN localhost

   <Directory /Applications/mampstack-5.4.20-0/apache2/htdocs/yourDefaultHttpFolder>
      RewriteEngine on
      RewriteCond %{SERVER_PORT} ^80$
      RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]
   </Directory>

</VirtualHost>

<VirtualHost *:8080> 
    DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/mext-pst-dashboard/web"
    ServerName mext-pst.local
    ServerAlias mext-pst.local
    SetEnv APPLICATION_ENV    development
    SetEnv APPLICATION_DOMAIN mext-pst.local       
 </VirtualHost>

This configuration is working on my server, when ever I try to access using 80 it rewrites the URL to my 8080 port and I see the content of that folder, not the the default index page.

like image 68
Özgür Eroğlu Avatar answered Oct 13 '22 11:10

Özgür Eroğlu


You've got to change the port to *:80 and also if you're going to use a different name then the servername make sure to take up NameVirtualHost *:80 in your httpd.conf.

like image 34
Jdeboer Avatar answered Oct 13 '22 10:10

Jdeboer