web服務(wù)器 - 在本機(jī)部署gitlab后,如何在nginx上配置多域名?
問題描述
之前在本機(jī)上部署了gitlab服務(wù),可以通過localhost、127.0.0.1 和本機(jī)IP訪問到本機(jī)gitlab頁(yè)面。
現(xiàn)在想在本機(jī)建立一個(gè)網(wǎng)站做些測(cè)試,可是不知道怎么訪問到新建的網(wǎng)站,搜索了相關(guān)資料,據(jù)說要修改nginx的配置文件,我在配置文件里添加 myhome.cn 域名,并綁定到網(wǎng)站目錄,可是訪問 myhome.cn 后,打開的還是gitlab的頁(yè)面。
按照網(wǎng)上的相關(guān)說明,我又修改了gitlab的配置文件:
/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml/opt/gitlab/embedded/service/gitlab-shell/config.yml
把 host 改成了 git.test.com,用gitlab-ctl restart命令重新啟動(dòng)gitlab后效果也一樣。
/etc/hosts里也添加了域名:
127.0.0.1 git.test.com127.0.0.1 myhome.cn
然而,并沒有什么用,不管什么域名,都是訪問gitlab的頁(yè)面,有沒有什么解決方法?
用ps -ef | grep nginx命令看了下,發(fā)現(xiàn)運(yùn)行的nginx的路徑是/opt/gitlab/embedded/sbin/nginx,而配置文件路徑是/var/opt/gitlab/nginx,怪不得我打開/etc/nginx/nginx.conf沒看到gitlab相關(guān)的配置。試著改了下/var/opt/gitlab/nginx/nginx.conf 和 /var/opt/gitlab/nginx/gitlab-http.conf,重啟服務(wù)后,頁(yè)面無法訪問了,我先折騰一下。
在/var/opt/gitlab/nginx/nginx.conf開頭處有這樣的內(nèi)容:
# This file is managed by gitlab-ctl. Manual changes will be# erased! To change the contents below, edit /etc/gitlab/gitlab.rb# and run `sudo gitlab-ctl reconfigure`.
呃,原來可以通過修改/etc/gitlab/gitlab.rb來配置,我再折騰一下。
問題解答
回答1:server {listen 80;server_name git.test.com;access_log /var/log/nginx/XXX.access_log main;error_log /var/log/nginx/XXX.error_log info;root /home/www/xxx;index index.html index.php;//接下來配置github cgi接口}server {listen 80;server_name myhome.cn;access_log /var/log/nginx/XXX.access_log main;error_log /var/log/nginx/XXX.error_log info;root /home/www/xxx2;index index.html index.php;//接下來配置別的cgi接口}回答2:
兩個(gè)nginx并存就好了,只要port不沖突就沒有問題。
回答3:能問下最終怎么解決的嗎?非常感謝,碰到同樣問題。
回答4:我也碰到這個(gè)問題,頁(yè)面無法訪問了
