Apache & Nginx on same Server leads to conflict with gitlab - apache

I tried to install Gitlab on my webserver. I configured everything appropriately. This is a scheme of what I am trying to achieve:
example.com:80 (default host)
vhost1.example.com:80 (a virtual host)
example.com:8080 (gitlab)
So what happens is this: I can open example.com and vhost1.example.com normally. If gitlab-ctl is stopped, I get a "Website not available"-error if I try to open example.com:8080 (as expected). When I start gitlab and try to open example.com:8080 again, it shows me the gitlab-error "502 Error GitLab is taking too much time to respond", but only the first time I load this page, as soon as I refresh or try it again in a new tab, it redirects my request always to example.com, although I request the page with ":8080" at the end.
I have access to gitlab with http://x.x.x.x:8080. This works but I'm forced to configure http://example.com:8080
System:
Debian Wheezy
Apache/2.2.22
gitlab-ce_8.4.1-ce (includes nginx)
Here are my configuration files:
/etc/apache2/sites-available/example.com
<VirtualHost *:80>
ServerAdmin mail#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error_example.com.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/sites-available/vhost1.example.com
<VirtualHost *:80>
ServerAdmin mail#example.com
ServerName vhost1.example.com
ServerAlias www.vhost1.example.com
DocumentRoot /var/www/vhost1.example.com
ErrorLog ${APACHE_LOG_DIR}/error_vhost1.example.com.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/vhost1.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/ports.conf (only changes)
NameVirtualHost *:80
Listen x.x.x.x:80
<IfModule mod_ssl.c>
Listen x.x.x.x:443
</IfModule>
<IfModule mod_gnutls.c>
Listen x.x.x.x:443
</IfModule>
/etc/gitlab/gitlab.rb (only changes)
external_url 'http://example.com:8080'
unicorn['port'] = 8081
nginx['listen_addresses'] = ["x.x.x.x"]
nginx['listen_port'] = 8080
netstat -napl | grep :80
tcp 0 0 x.x.x.x:8080 0.0.0.0:* LISTEN 19037/nginx
tcp 0 0 x.x.x.x:80 0.0.0.0:* LISTEN 18280/apache2
tcp 0 0 127.0.0.1:8081 0.0.0.0:* LISTEN 19110/config.ru
I would really appreciate every hint. If you need further information just ask.

After some tinkering I found a solution that worked for me. If someone has the same problem here you go:
Apache was configured correctly, so the configuration stays as is.
/etc/apache2/sites-available/example.com
<VirtualHost *:80>
ServerAdmin mail#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error_example.com.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/sites-available/vhost1.example.com
<VirtualHost *:80>
ServerAdmin mail#example.com
ServerName vhost1.example.com
ServerAlias www.vhost1.example.com
DocumentRoot /var/www/vhost1.example.com
ErrorLog ${APACHE_LOG_DIR}/error_vhost1.example.com.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/vhost1.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/apache2/ports.conf (only changes)
NameVirtualHost *:80
Listen x.x.x.x:80
<IfModule mod_ssl.c>
Listen x.x.x.x:443
</IfModule>
<IfModule mod_gnutls.c>
Listen x.x.x.x:443
</IfModule>
The problem existed because of the gitlab.rb configuration. The solution is not to change too much. Only these two lines are needed for gitlab to work:
/etc/gitlab/gitlab.rb (only changes)
external_url 'http://git.example.com:8080'
unicorn['port'] = 8081
If you're not planning to run Gitlab on Port 8080, you don't have to assign a new port for unicorn. Do not forget to run 'gitlab-ctl reconfigure' after the changes.

Related

Use of SSL Cert results in ERR_ADDRESS_UNREACHABLE on ubuntu with apache2

Tried to use the ssl cert and key I got from my provider but it's not working out. When I want to connect to my site I get an ERR_ADDRESS_UNREACHABLE in Google Chrome.
Here is my Apache Config for the website.
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
ServerAdmin me#example.com
DocumentRoot /var/www/example.com/public
Redirect "/" "https://example.com/"
ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias *.example.com
ServerAdmin me#example.com
DocumentRoot /var/www/example.com/public
SSLEngine on
SSLCertificateFile /etc/ssl/certs/example.com.crt
SSLCertificateKeyFile /etc/ssl/private/example.com.key
<Directory /var/www/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
<Limit POST PUT DELETE>
Require all granted
</Limit>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined
</VirtualHost>
</IfModule>
I also ensured that the firewall allowes https connections.
What am I missing here?
Ok, so strangely ssl/https/port 443 was indeed NOT enabled on my server. Don't know why everything tells me that https is enabled but here is how I could solve it for me.
iptables -I INPUT -p tcp --dport 443 -j ACCEPT

httpd.conf configuration issue

I'm currently migrating a bunch of websites to amazon ec2 (running on the Amazon Linux AMI), and am having difficulties getting Apache's VirtualHost configuration to work.
Here's what my httpd.conf file looks like:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/sites/example.com/
<Directory /home/sites/example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/example.com.error.log
LogLevel warn
CustomLog /var/log/httpd/example.com.access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /home/sites/blog.example.com/
<Directory /home/sites/blog.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/blog.example.com.error.log
LogLevel warn
CustomLog /var/log/httpd/blog.example.com.access.log combined
</VirtualHost>
Here's the result of httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 example.com (/etc/httpd/conf.d/ssl.conf:74)
*:80 is a NameVirtualHost
default server example.com (/etc/httpd/conf/httpd.conf:1012)
port 80 namevhost example.com (/etc/httpd/conf/httpd.conf:1012)
port 80 namevhost blog.example.com (/etc/httpd/conf/httpd.conf:1029)
Syntax OK
However, if I attempt to go to blog.example.com, I get a ERR_NAME_NOT_RESOLVED response.
If I change the first VirtualHost definition to blog.example.com, I can load the blog.example.com site, so both sites are working, leading me to suspect I either have configured something wrong in VirtualHost, or on the end of my domain registrar.
My issue was that I had the example.com domain before the blog.example.com domain, meaning everything just went to example.com. Order matters!

Name and IP Virtual Host on Apache

I am trying to direct web traffic for our domain to a Vhost site and our internal web site to separate directory that is only accessible within our private network,i.e 192.168.x.x.
I have modified Vhost configuration on Apache to include a name-based Vhost for the external website and a IP Vhost for the Intranet. No far I have had no luck, Apache does not like it.
Here is my modified Vhost config file.
NameVirtualHost *:80
<Directory "/home/webs">
Options +FollowSymLinks +Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot /home/webs/foo
ServerName www.foo.com
ServerAlias foo.com
LogLevel warn
ErrorLog /home/webs/foo/error.log
CustomLog /home/webs/foo/logs/access.log combined
</VirtualHost>
NameVirtualHost 192.168.0.*:80
<Directory "/home/webs/OffCat">
Options +FollowSymLinks +Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost 192.168.0.*:80>
DocumentRoot /home/webs/OffCat
ServerName 192.168.0.15/OffCat
LogLevel warn
ErrorLog /home/webs/OffCat/logs/error.log
CustomLog /home/webs/OffCat/logs/access.log combined
</VirtualHost>
I would appreciate any help.
Thanks,
Tony Cripps

Apache 2.2 VirtualHosts URL not found

I'm hoping you can help. I have an existing Apache 2.2 server which serves a website I maintain. I am attempting to add additional websites for a colleague. Having done so, I get the following when I attempt to access the URL:
Not Found The requested URL / was not found on this server.
Here's a summary of my httpd-vhosts.conf file. I have three new, roughly identical, hosts that aren't working. Only NDV and the default are working.
NameVirtualHost *:80
<VirtualHost anycast.ns.cs.boeing.com:80>
ServerName anycast.ns.cs.boeing.com
ServerAdmin aodhan.hoffman#boeing.com
DocumentRoot "/opt/www/anycast"
ScriptAlias /cgi-bin "/opt/www/anycast/cgi-bin/"
ErrorLog "logs/grant_error_log"
CustomLog "logs/grant_access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin aodhan.hoffman#boeing.com
DocumentRoot "/opt/httpd/manual"
ServerAlias ntpm-application-01.ns.cs.boeing.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin aodhan.hoffman#boeing.com
DocumentRoot "/opt/www/ndv/html"
ServerName ndv.web.boeing.com
ScriptAlias /cgi-bin/ "/opt/www/ndv/cgi-bin/"
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
<Directory "/opt/www/ndv/html/" >
Options Indexes FollowSymLinks Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Order allow,deny
Allow from all
</Directory>
<Directory "/opt/www/anycast/html/" >
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
</Directory>
Based on the config above, this is what the server is seeing.
$ sudo bin/apachectl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server ntpm-application-01.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:30)
port 80 namevhost ntpm-application-01.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:30)
port 80 namevhost ndv.web.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:39)
port 80 namevhost anycast.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:48)
port 80 namevhost ntpget.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:60)
port 80 namevhost dnsdig.ns.cs.boeing.com (/opt/httpd/conf/extra/httpd-vhosts.conf:70)
Syntax OK
You seem to mix configuration approaches:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
This is the example from the Apache Docs regarding name based VHosts.
I can see in your config VirtualHost without the * -> anycast.ns.cs.boeing.com:80
as well as VHosts without a server name like ServerAlias ntpm-application-01.ns.cs.boeing.com
which has an alias, but no name.
I would start to even out the configurations like in the example and then try if the apache is more happy with that.
In short: Make sure each of you entries have *:80 and a server name.
Edit: This config is not tested but might work for you
NameVirtualHost *:80
<VirtualHost *:80>
ServerName anycast.ns.cs.boeing.com
ServerAdmin aodhan.hoffman#boeing.com
DocumentRoot "/opt/www/anycast/html"
ScriptAlias /cgi-bin "/opt/www/anycast/cgi-bin/"
ErrorLog "logs/grant_error_log"
CustomLog "logs/grant_access_log" common
<Directory "/opt/www/anycast/html/" >
Options Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName ntpm-application-01.ns.cs.boeing.com
ServerAdmin aodhan.hoffman#boeing.com
DocumentRoot "/opt/httpd/manual"
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName ndv.web.boeing.com
ServerAdmin aodhan.hoffman#boeing.com
DocumentRoot "/opt/www/ndv/html"
ScriptAlias /cgi-bin/ "/opt/www/ndv/cgi-bin/"
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
<Directory "/opt/www/ndv/html/" >
Options Indexes FollowSymLinks Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
My advise is to open and read all the logs that apache generates. That will give you a clue of where the problem lies. I read the log at "/private/var/log/apache2/error_log" in a mac and found my clue: DocumentRoot [/path/to/rootdir] does not exist.
I opened the vhost file and found out that instead of encapsulating the root directory in double quotes I had used other characters that seemed like double quotes. I replaced them by the real double quotes, restarted apache and then the error was gone.
What worked for me is uninstalling and upgrading (in my case Wampserver) the software that you're using.

How to set up virtual hosts on Apache 2.2

Can anyone direct me to a good tutorial on how to set up virtual hosts using Apache 2.2? Here's my situation:
I have Apache running on my laptop and I want two websites-- one on port 80 and one on port 8089. I want to access each site from the other computer on my network by entering the computer's IP address, such as http://192.168.1.102 and http://192.168.1.102:8089. Yet when I enter the second url, it directs me to the website running on port 80.
Thanks in advance for any help.
First you need to instruct Apache to listen on the ports you need:
Listen 80
Listen 8089
Second you need to tell it what to do with 80 and 8089 traffic:
<VirtualHost *:80>
DocumentRoot /website/site80
ServerName internet.dev
</VirtualHost>
<VirtualHost *:8089>
DocumentRoot /website/site8089
</VirtualHost>
Third you need to "allow" Apache to use those directories:
<Directory "C:/website/site80">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:/website/site8089">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Just have 2 virtual hosts defined like this, but with differeing DocumentRoots:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.somecompany.com
DocumentRoot "/docs/dummy-host.somecompany.com"
ServerName dummy-host.somecompany.com
ServerAlias www.dummy-host.somecompany.com
ErrorLog "logs/dummy-host.somecompany.com-error.log"
CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>
<VirtualHost *:8089>
ServerAdmin webmaster#dummy-host.somecompany.com
DocumentRoot "/docs/dummy-host.somecompany.com"
ServerName dummy-host.somecompany.com
ServerAlias www.dummy-host.somecompany.com
ErrorLog "logs/dummy-host.somecompany.com-error.log"
CustomLog "logs/dummy-host.somecompany.com-access.log" common
</VirtualHost>