apache2 VirtualHost on a new port not working - apache

I just installed LAMP on my Ubuntu machine, and it works fine when I access it. I want to add a virtual host on another port, port 1337, that goes to the directory /var/www/flag-1/. In order to do this, I take the following steps:
cd /etc/apache2/sites-available/
Created a file flag-1.conf
Added contents:
<VirtualHost *:1337>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/flag-1/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
At the top of /etc/apache2/ports.conf, after Listen 80, added Listen 1337
Enabled the vhost site by doing a2ensite flag-1.conf
Reloaded apache service apache2 restart
When I access the site with port 1337, it just loads indefinitely. The default port still works fine, and I don't have UFW enabled. No errors, nothing in access.log or error.log is outstanding.
Any help is appreciated. Thanks!

Figured it out -- I was using Google Cloud Platform and they blocked port 1337, I just had to manually allow TCP through it.
If you're wondering, the command was
gcloud compute firewall-rules create allow-port-1337 --allow tcp:1337 --description="Allow port 1337 to be accessed"

Related

Config VirtualHosts on Debian/Apache

On my debian/apache server at http://localhost I'm redirected to my api on port 3000 (this is ok)
Now I would like to open another port (8090), in http://localhost:8090 redirected to /var/www/html/
How to make?
Find the default virtual host conf file by running
ls /etc/apache2/sites-available/
There should be a file called deault.conf, or similar. We want to edit this file
sudo nano /etc/apache2/sites-available/default.conf
Make sure that apache actually is listening to your port 8090 by adding, to the top of that document
Listen 8090
Change the rest of the conf file to match your site, so it may look something like this
Listen 8090
<VirtualHost *:8090>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
# Other directives here
</VirtualHost>
Save the file with a different name in the same folder. The files must end with ".conf". Add the virtual host to enabled sites by running
sudo a2ensite virtual_host_file_name.conf
replacing "virtual_host_file_name.conf" with the name of the file you select in the previous step.
Then restart the apache server
sudo service apache2 reload
It seems like you're only interested in accessing it from localhost, but if you want to access it remotely you might need to check your firewalls.

Apache: Serving content from two different locations and ports

I have an Apache server running on Ubuntu 14 on a server on which I have sudo.
When users request the server's IP, Apache serves content from /var/www/html.
I'd like to keep this behavior intact, and make it so that users who request IP/cats get some special content that's hosted by a Docker container on port 7777.
What's the best way to achieve this functionality in Apache?
With thanks to #arkascha I did the following to get this going:
Create a file /etc/apache2/sites-available/wow.conf with the following content:
<VirtualHost *:*>
# enable proxies
ProxyPreserveHost On
ProxyPass /cats http://0.0.0.0:7777/
ProxyPassReverse /cats http://0.0.0.0:7777/
ServerAdmin douglas.duhaime#yale.edu
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This says when requests come in for IP/cats, serve the users the content from port 7777.
I then symlinked this file to the sites-enabled directory:
sudo ln /etc/apache2/sites-available/wow.conf /etc/apache2/sites-enabled/wow.conf
Finally, I needed to delete the default sites enabled file and restart the server:
sudo rm /etc/apache2/sites-enabled/000-default.conf
sudo service apache2 restart
P.S. Apache is amazing.

VirtualHosts Not Working for Locally Hosted Apache Web Server

I have an apache web server setup on my development machine (macos sierra). The configuration I had setup has been working fine for months, but for some reason it decided to stop working today. I have to include the port number (i.e. mysite.local.com:8080) for any locally hosted site I want to navigate to. If I leave off the port number I get ERR_EMPTY_RESPONSE in the browser. The config test is passing with no errors. I haven't upgraded or changed anything on this machine (that I can recall) that would cause virtual hosts to stop working. Can anyone suggest a way to pin down what the issue is here?
FYI
sudo apachectl -S produces
VirtualHost configuration:
*:87 bto.local.tura.com (/private/etc/apache2/sites-enabled/bto.local.tura.com.conf:2)
*:8080 is a NameVirtualHost
default server mr.local.tura.com (/private/etc/apache2/sites-enabled/mr.local.tura.com.conf:1)
port 8080 namevhost mr.local.tura.com (/private/etc/apache2/sites-enabled/mr.local.tura.com.conf:1)
port 8080 namevhost optics.local.tura.com (/private/etc/apache2/sites-enabled/optics.local.tura.com.conf:1)
*:85 overstock.local.tura.com (/private/etc/apache2/sites-enabled/overstock.local.tura.com.conf:1)
*:86 static.local.tura.com (/private/etc/apache2/sites-enabled/static.local.tura.com.conf:1)
My httpd.conf:
Listen 8080
Listen 85
Listen 86
Listen 87
...
ErrorLog "/var/log/apache2/error.log"
...
Include /private/etc/apache2/sites-enabled/*.conf
An example of a vhhost config file:
<VirtualHost *:85>
ServerName overstock.local.tura.com
DocumentRoot /usr/local/web/overstock
ErrorLog /var/log/apache2/overstock.local.tura.com.error.log
CustomLog /var/log/apache2/overstock.local.tura.com.access.log "combined"
<Directory "/usr/local/web/overstock">
Order Deny,Allow
Deny from all
Allow from all
Options -Indexes +FollowSymLinks
</Directory>
LogLevel emerg
</VirtualHost>
I think you should add
Listen 80
try by changing deny from none in place of deny from all
what are errors from /var/log/apache2/error.log ,paste the content of error.log

Why I see the content of my localhost instead of accessing my created virtual host?

I'm working on Ubuntu-14 and I want to access http://localhost:8086/myproject.net using http://myproject.dev
I created a new folder under "/var/www/" named "myproject.net"
I added this line to "/etc/hosts"
127.0.0.1 myproject.dev
I created "myproject.dev.conf" file under "/etc/apache2/sites-available" which contains:
<VirtualHost *:86>
ServerAdmin i-put-my-email-here
ServerName myproject.dev
ServerAlias www.myproject.dev
DocumentRoot /var/www/myproject.net/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I enabled my site using
sudo a2ensite myproject.dev.conf
I restarted Apache
sudo service apache2 restart
I verified that Apache is running using
sudo service apache2 status
Now when I tape http://myproject.dev:8086 I see the content of my localhost (like when I do http://localhost:8086) not the content of myproject!
Am I missing a step or Am I doing something wrong?
You have to take care to define your virtual host on the correct address and port so that it can be matched for an incoming request. Otherwise the default host will be selected to respond to the request.
In your specific example you have to change the definition from
<VirtualHost *:86>
to use the port your http server is obviously listening on and that you make the request to:
<VirtualHost *:8086>
Oh, and... don't forget to restart your http server process after such a change ;-)

Connection to localhost fails

I set up /etc/apache2/extra/httpd-vhosts.conf as follows:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
In /Library/WebServer/Documents/ is the standard index.html.en file which was shown perfectly in the browser before I included the httpd-vhosts.conf into my httpd.conf.
The connection to localhost fails using both, Chrome and Firefox. Is the setup correct? What else could go wrong?
I solved the problem. I couldn't state further information because I just didn't know where I could look for the problem. This post put me in the right way:
http://macosx.com/forums/mac-os-x-system-mac-software/299851-apache-wont-start-up.html
sudo apachectl configtest
Gave me an syntax error within the httpd.conf file. After fixing it everything worked. The important thing is the opportunity to run a configtest.