2013-08-22 22 views
0

我已成功配置nginx。与默认网站它工作正常。 现在我有2个网站,一个在/ home/bugz和另一个/ home/git/github/public。只有一个IP 10.10.10.10(我没有DNS设置,因此不能使用域名) 我想有网站在位置服务nginx一个ipaddress但从子文件夹服务的2个站点

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

是两个配置文件

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; 
     } 
} 

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; 
    } 

    } 

我该如何做到这一点?

+0

只配置1个网站,你在你的config目录使用'网站,available'? – ProfessionalAmateur

+0

是我的配置文件中使用的站点可用 – sparkbird

回答

0

nginx.conf应该包含这样的事情http块中:

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

那么你将在/etc/nginx/sites-available文件夹2个配置文件。 (其具有从sites-enabled文件夹的符号链接指向

每个CONF要么需要具有它们监听一个不同的端口;即,一个在端口80和一个端口81

server1.conf

server { 
    listen  80; 
    server_name localhost; 

server2.conf

server { 
    listen  81; 
    server_name localhost; 

- 或 -

为conf文件中的每台服务器安装不同的servername并与hosts文件一起播放。

+0

我也可以启用/ etc/nginx/sites-available,并且在启用站点的站点中有适当的符号链接。 – sparkbird

+0

我也可以启用/ etc/nginx/sites-available并且在启用了站点的地方有适当的符号链接。 我不想在2 diff端口上有两个diff站点。他们在同一个港口80上工作。 你能解释第二个选项吗?我怎么能有不同的服务器名称?我只有一个界面10.10.10.10(没有DNS配置,因此无法使用主机名称) 当你说“玩主机文件”你在暗示什么,你能解释一下,我对nginx很新。在apache很容易,把这两个站点放在/ var/www /下的2个文件夹下。我们有没有类似的nginx? – sparkbird

+0

如果你没有DNS设置,我不相信这会起作用。你需要告诉ngnix监听不同的主机名/服务器名。单独使用IP地址不足以支持同一端口上的两个站点。 – ProfessionalAmateur

0

我不明白为什么这个巨大CONFIGS,我会用2个位置

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 { } 
} 
相关问题