Question

I recently bought a linode 1GB plan. Installed Apache on it, had my website up and running on it. However I installed gitlab on the server and mapped it to a sub-domain. Since the installation guides recommended using Nginx as the server, I installed it and is running on port 80. Currently my apache is not running since there are port conflicts. But I fixed it by editing the /etc/apache2/ports.conf file and instructing apache to serve on a different port. Now when I visit the main domain that is pointing to a port(8000) and using apache doesn't show up. gitlab is installed at http://gitlab.myserver.com and I am able to access it., but if I try to navigate to http://myserver.com, I get the content of http://gitlab.myserver.com

My gitlab config serving under Nginx is as follows:

# GITLAB
# Maintainer: @randx
# App Version: 5.0

upstream gitlab {
 server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen my_server_ip default_server;  # e.g., listen 192.168.1.1:80; In most    cases *:80 is a good idea
  server_name gitlab.myserver.com;         # e.g., server_name source.example.com;
  server_tokens off;     # don't show the version number, a security best practice
  root /home/git/gitlab/public;

# individual nginx logs for this gitlab vhost
access_log  /var/log/nginx/gitlab_access.log;
error_log   /var/log/nginx/gitlab_error.log;

location / {
  # serve static files from defined root folder;.
  # @gitlab is a named location for the upstream fallback, see below
  try_files $uri $uri/index.html $uri.html @gitlab;
}

# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {
  proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  proxy_connect_timeout 800; # https://github.com/gitlabhq/gitlabhq/issues/694
  proxy_redirect     off;

  proxy_set_header   X-Forwarded-Proto $scheme;
  proxy_set_header   Host              $http_host;
  proxy_set_header   X-Real-IP         $remote_addr;

  proxy_pass http://gitlab;
 }
}

My Apache config for myserver.com is as follows:

# domain: myserver.com
# public: /home/me/public/myserver.com/

<VirtualHost *:8000>
 # Admin email, Server Name (domain name), and any aliases
 ServerAdmin webmaster@myserver.com
 ServerName  www.myserver.com
 ServerAlias myserver.com

 # Index file and Document Root (where the public files are located)
 DirectoryIndex index.html index.php
 DocumentRoot /home/me/public/myserver.com/public

 # Log file locations
 LogLevel warn
 ErrorLog  /home/me/public/myserver.com/log/error.log
 CustomLog /home/me/public/myserver.com/log/access.log combined
</VirtualHost>

Where am I going wrong?

Was it helpful?

Solution 2

I solved the issue. The issue was with the following line in my gitlab config:

server {
  listen my_ip default_server;
  server_name gitlab.myserver.com;         # e.g., server_name source.example.com;
  server_tokens off;     # don't show the version number, a security best practice
  root /home/git/gitlab/public;
  ......
}

I changed this to the following:

server {
      listen 80;
      server_name gitlab.myserver.com;         # e.g., server_name source.example.com;
      server_tokens off;     # don't show the version number, a security best practice
      root /home/git/gitlab/public;
      ......
    }

And I followed your instructions on serving sites on apache via nginx by using proxy_pass

Thanks a lot.. Cheers....

OTHER TIPS

A good solution is to continue to run Nginx on port 80, while adding proxy directives to Nginx to serve as a proxy for specific domains that are running on Apache. An example Nginx configuration:

server {
    server_name  www.myserver.com;
    server_name myserver.com;

   location / {
      proxy_pass http://127.0.0.1:8000;
   }
}

I do this myself, and it works great.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top