2013-08-22 32 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 { } 
} 
相關問題