sparkbird
sparkbird

Reputation: 21

nginx one ipaddress but 2 sites served from subfolder

I have succesfully configured nginx. with default site it works correctly. Now i have 2 sites, one at /home/bugz and another one /home/git/github/public. and only one ip 10.10.10.10 (i dont have dns setup hence cant use domain names) i want to have the sites served at locations

http://10.10.10.10/bugz and http://10.10.10.10/github respectively

below are the two config files

server {
  listen  *:80;
  server_name 10.10.10.10;
  server_tokens off;
  root /home/bugz;

   # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/bugzilla_access.log;
  error_log   /var/log/nginx/bugzilla_error.log;

  location /bugz {
      index  index.html index.htm index.pl;
  }


  location ~ \.pl|cgi$ {
      try_files $uri =404;
      gzip off;
      fastcgi_pass  127.0.0.1:8999;
      fastcgi_index index.pl;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include fastcgi_params;
      }
}

and

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

server {
#  listen *:80 default_server;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  listen *:80;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  server_name 10.10.10.10;     # 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 300; # 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;
  }

  }

How do i achieve this ?

Upvotes: 0

Views: 2975

Answers (2)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42799

I don't understand why this huge configs, I'd configure only 1 site with 2 locations

server {
    server_name 10.10.10.10;
    location /bugz {
        root /root/to/bugz;
        access_log  /var/log/nginx/bugzilla_access.log;
        error_log   /var/log/nginx/bugzilla_error.log;
        index  index.html index.htm index.pl;
        # try_files statement
    }
    location /git {
        root /home/git/gitlab/public;
        #access and error log and rest of config
    }
    location ~ \.pl|cgi$ { }
    location @gitlab { }
}

Upvotes: 0

ProfessionalAmateur
ProfessionalAmateur

Reputation: 4563

Your nginx.conf should contain something like this inside the http block :

 include /etc/nginx/sites-enabled/*;

Then you will have 2 configuration files in the /etc/nginx/sites-available folder. (which has symlinks directed from the sites-enabled folder.

Each conf will need to either have them listening on a different ports; ie one on port 80 and on one port 81

server1.conf

server {
    listen       80;
    server_name  localhost;

server2.conf

server {
    listen       81;
    server_name  localhost;

-OR-

Have a different servername for each server in the conf files and play with the hosts file.

Upvotes: 1

Related Questions