Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to configure gitlab running in an Ubuntu 12.04 guest with Windows7 host. I can ssh the guest using port-forwarding and access the nginx server using port redirection (8888 in host is 80 in guest, so localhost:8888 in host gets to the nginx server in the guest), but the server_name in nginx configuration file is giving me trouble. What is the correct listen and server_name that nginx would accept?

The guest has the NAT interface at 10.0.2.15 and Host-Only interface at 192.168.56.101, static.

Thanks!

EDIT: Because the host uses a static ip address I can't use bridged mode for the Ubuntu guest, so I have to stick with Host-Only and Port Forwarding. With this I can access the nginx server in the guest, but server_name is still wrong, as I have to use localhost:8888 in the Windows host and forward it to port 80 in the guest. What should be server_name?

share|improve this question
add comment

2 Answers

nginx will look at the name given in the url to reach the server and compare to the servername. You have to use the guest machine hostname to reach it and use it as servername. Another way is to use a local DNS or hosts file to supply the right IP for your guest system hostname (or any uri you want - a website in development for example) and use this hostname or uri as servername.

To use a server on guest, I would suggest to use bridge mode instead of NAT so you don't need port forward and avoid a lot of small complications. (Obs: I'm not saying you can't work with NAT but I find easier to use bridge)

share|improve this answer
    
I tried to use bridged mode, but them the Windows host can't find the guest on any port. Any suggestions on this side? The docs doesn't show anything for this case. –  Ivan Dec 12 '12 at 19:43
    
Also, I changed the second NIC to bridged. The Windows host has ip 192.168.56.1 and the ubuntu guest has eth1 at 192.168.56.101, but they can't see each other. Is there anything else that needs to be configured? Thanks –  Ivan Dec 12 '12 at 22:21
    
They should see each other if they are on the same subnet without problem... I never used the host on windows but with the host on ubuntu there is nothing to configure so I imagine it should be the same. You can't ping the IP directly or only by name? If it is reachable by IP, this is a name resolution problem so if you have no local DNS, you could use the host file of the windows machine (in C:\WINDOWS\system32\drivers\etc\hosts on winxp - should be similar on win7...) to supply the right IP for your guest (the syntax is the same as on linux). –  laurent Dec 13 '12 at 0:52
    
The problem here is that the host has an real and static ip address, so I can't use bridged network. Gonna have to settle with host-only and port forwarding. –  Ivan Dec 13 '12 at 14:37
    
So with NAT, your guest is not in the subnet routed by your router. No problem, you only will need to route to the host and the host will need to route the guest. By real IP you mean public static IP? If this is the case, it can't be behind a NAT. –  laurent Dec 13 '12 at 18:46
add comment
up vote 1 down vote accepted

Thanks for the help, laurent!

I ended up leaving this configuration in nginx:

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


server {
  listen 80 default;         # e.g., listen 192.168.1.1:80;
  #server_name thinkstation-ubuntu;     # e.g., server_name source.example.com;
  root /home/gitlab/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;
  }
}

And it works! The final configuration is:

Windows7 host: Host-only interface created, ip 192.168.56.1, port forwarding configured: host 8888 to guest 80

Ubuntu 12.04 Server guest: nginx running, eth0 as VirtualBox NAT, eth1 with Host-only, with static ip 192.168.56.101

Ubuntu 12.04 Desktop: eth0 as Virtualbox NAT, eth1 with Host-only with static ip 192.168.56.102, accessing directly 192.168.56.101 nginx, ssh, all the services.

Thanks!

share|improve this answer
1  
I think this works because you have defined it as listen 80 default; (without servername and with default). This way nginx will answer to anything that come on its port 80. If you intend to run other sites on the future using this nginx instance you will have to define them differently but for now it works! ;) –  laurent Dec 14 '12 at 16:57
    
Off topic, but Laurent helped you solve the problem and you posted your own answer and accepted your answer? I think you should have edited your question and included the resolution and marked his answer as accepted. Seems kind of odd to have someone help you and then accept the points yourself ... –  Bryan Ray Aug 22 '13 at 20:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.