VirtualHost setup always doesn't work VirtualHost setup always doesn't work apache apache

VirtualHost setup always doesn't work


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.


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.


Since you are not listening on port 80, getting an error when you go to the URL without a port seems to be the correct result, right?

And when you go to port 8080 you are getting a Proxy Error. Are you sure there is no other software running on port 8080 or your browser doesn't have a proxy entered? Apache would not be giving a Proxy Error. I suspect this error is coming from somewhere else.

About your configuration, I am not exactly sure what it is that you are trying to achieve but, if you are trying to get some documents served when you go to localhost:8080 and another set of documents served when you go to mext-pst.local:8080 than you are almost there, NameVirtualHost *:8080 is correct and needs to be there, remove redirect lines as you don't need them (unless my assumption is wrong).