How to listen ONLY on specified ports? - mamp

I have the following specified in my vhosts file:
Listen 8585
NameVirtualHost *:8585
Listen 8888
NameVirtualHost *:8888
<VirtualHost *:8888>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:8585>
DocumentRoot "/Applications/MAMP/htdocs/test"
ServerName www.test.me
ServerAlias test.me
</VirtualHost>
This works as follows:
localhost:8888 goes to the localhost location
localhost:8585 goes to the www.test.me location
test.me:8585 goes go the www.test.me location
test.me:8888 doesn't go anywhere
What I'd like is that localhost only responds on port 8888 and ignores 8585 (just like test.me listens on 8585 but ignores 8888).
Not sure if this is doable and if so, how to set this up. Thanks for any suggestions!

Related

Cannot set up multiple virtual hosts via MAMP

I'm trying to set up virtual hosts for the projects in my MAMP htdocs folder. But I cannot create more than one, it seems. If, for example, I have this in my httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/first-project/public"
ServerName first-project.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/second-project/public"
ServerName second-project.dev
</VirtualHost>
And I then point the browser to second-project.dev, it will show me the contents of first-project.dev. If I remove the v-host entry for first-project, then I can view second-project.dev with no problem. It doesn't like me having more than one entry, for some reason.
I have the following in my /etc/hosts file:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 first-project.dev
127.0.0.1 second-project.dev
255.255.255.255 broadcasthost
::1 localhost
Am I missing something? Maybe a setting in httpd.conf?
I found the answer to my own question. When establishing multiple virtual host entries, you need the following line before the entries:
NameVirtualHost *:80
Also, you need to establish the desired directory to replace the default localhost:
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/"
ServerName localhost
</VirtualHost>
My full httpd-vhosts.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/sampleapp/public/"
ServerName sampleapp.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/simplewebsite/public/"
ServerName simplewebsite.dev
</VirtualHost>

Ubuntu 14.04 Redirect Domain to Port

I am trying to direct mydomain.com to a specific port. I have run netstat and I know that my code is listening at 0.0.0.0:3000. I have the following in /etc/apache2/sites-available
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.com
ServerAlias www.mydomain.com
ProxyPass / http://0.0.0.0:3000/
ProxyPassReverse / http://0.0.0.0:3000/
</VirtualHost>
I was able to get other domains redirected to a subdirectory. When I test using mydomain.com from a browser, I see the default page.

How to redirect different URLs to different ports on the same domain?

I have odoo running on port 8069 and I want to run wordpress on port 80 on the same domain. I would like to redirect example.com* to port 8069 except example.com/wordpress* which I want to go to port 80.
I know this is similar to Redirecting from port 80 to different ports based on URL. I want to implement a reverse proxy solution as advised by abhi-devireddy. I tried the following reverse proxy. All requests are forwarded to port 8069 including http://example.com/wordpress/. Odoo reports error 404 page not found when browser points to http://example.com/wordpress
<VirtualHost *:80>
ServerName odoo
ErrorLog /var/log/odoo/odoo-error.log
CustomLog /var/log/odoo/odoo-access.log combined
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://example.com:8069/
ProxyPassReverse / http://example.com:8069/
ProxyPass http://example.com/wordpress/ http://example.com:80/wordpress
ProxyPassReverse http://example.com/wordpress/ http://example.com:80/wordpress
ProxyVia On
LogLevel warn
</VirtualHost>
ProxyPass ! excludes the URL http://example.com:80/wordpress from the reverse proxy. This allows everything except http://example.com:80/wordpress to be mapped to port 8069 while leaving http://example.com:80/wordpress to go through to port 80:
<VirtualHost *:80>
ServerName odoo
ErrorLog /var/log/odoo/odoo-error.log
CustomLog /var/log/odoo/odoo-access.log combined
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPass /wordpress !
ProxyPass / http://example.com:8069/
ProxyPassReverse / http://example.com:8069/
Alias /wordpress /var/lib/wordpress/
# ProxyVia On
LogLevel warn
</VirtualHost>

How to rewrite a domain to a subfolder

I have one local server called server1 with a subdirectory sub (server1/sub/).
Now i have a dns entry which redirects server2 to server1.
I want to configure my apacher server in a way that when I open server2 in a browser I get the content from server1/sub/.
The url should not change to server1/sub/.
Is this possible with mod_rewrite?
EDIT:
I added
127.0.0.1 localhost
127.0.0.1 wiki2
127.0.0.1 wiki3
to the hosts file and
VirtualHost 127.0.0.1>
ServerName wiki2
ServerAlias 127.0.0.1
DocumentRoot c:/xampp/htdocs/wiki_angua
<Directory c:/xampp/htdocs/wiki_angua >
Allow From All
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName wiki3
ServerAlias 127.0.0.1
DocumentRoot c:/xampp/htdocs/weatherwax
<Directory c:/xampp/htdocs/weatherwax >
Allow From All
</Directory>
</VirtualHost>
to httpd.conf and restarted apache.
Whether I open wiki2 or wiki3 I land in ./wiki_angua.
Is there anything I forgot?
If you have a DNS entry for server2 then the Host HTTP request header will be correctly set, and all you need then is a virtual host, without the need to use mod_rewrite.
For example:
<VirtualHost *:80>
ServerName server2
DocumentRoot /path/to/server1/sub
<Directory /path/to/server1/sub>
Allow From All
</Directory>
# ... etc
</VirtualHost>
edit:
In the case you still want to use mod_rewrite you can do something like:
RewriteCond %{HTTP_HOST} ^server2$
RewriteRule ^(.+) /path/to/server1/sub/$1
This must be located in the global server configuration, and not in an existing virtual host.

Apache redirects www.domain.com to domain.com/domain

I'm preparing my ubuntu server in Amazon AWS to host a new website. It uses Apache2. I've done this before with no problem whatsoever, for example, to trick a friend I spoofed google.com and www.google.com (editing his hosts file) and everything worked fine with and without 'www.'.
Now I have bought a domain name 'domain.com' with 1&1 , I have configured a subdomain 'www.domain.com' and I have pointed it to my server. The dns record is fine, I checked. I have also edited my sites-enabled default file and added these entries:
<VirtualHost *:80 >
ServerName www.domain.com
DocumentRoot /var/www/domain
</VirtualHost>
<VirtualHost *:80 >
ServerName domain.com
DocumentRoot /var/www/domain
</VirtualHost>
When I visit domain.com in my browser it works fine, but when I visit www.domain.com I get domain.com/domain/ and obviously a 404.
I used telnet and discovered that the server sends a 301 when you request the root page of host: www.domain.com
I don't know why this is happening, I've tried lots of modifications to the configuration above like:
<VirtualHost *:80 >
ServerAlias www.domain.com
DocumentRoot /var/www/domain
</VirtualHost>
<VirtualHost *:80 >
ServerAlias domain.com
DocumentRoot /var/www/domain
</VirtualHost>
.
<VirtualHost *:80 >
ServerName domain.com
DocumentRoot /var/www/domain
</VirtualHost>
<VirtualHost *:80 >
ServerName www.domain.com
DocumentRoot /var/www/domain
</VirtualHost>
.
<VirtualHost *:80 >
ServerName domain.com
Server Alias www.domain.com
DocumentRoot /var/www/domain
</VirtualHost>
but it kept happening.
For the record, this is what I used for the spoof that still works fine
<VirtualHost *:80 >
ServerName google.com
DocumentRoot /var/www/google
</VirtualHost>
<VirtualHost *:80 >
ServerName www.google.com
DocumentRoot /var/www/google
</VirtualHost>
I've been searching for two days now, but all I find is the same configuration I'm using and no explanation about why this isn't working.
Thanks for your help!
PS: There are no .htaccess files in this directory or in any of the parent directories.
In case anybody enters this question.
I still don't know what was wrong but after moving these configurations around the file they've magically started working normally.
Thanks to everybody who took the time to read the question.
Its better to put
<VirtualHost *:80 >
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain
</VirtualHost>
You can't put a space between Server and Alias so I changed to show you
Hope It Works!