默认情况下,GitLab会安装nginx,但通常不会将nginx添加到系统的服务管理器(service或systemctl)。这使得在尝试启用Apache时变得困惑(由于默认端口80被nginx使用,Apache无法启动)。
假设您已按照默认安装说明安装了Gitlab,则Nginx服务现在将由gitlab-ctl服务管理器(安装Gitlab时安装)管理。
要停止Nginx,请以root身份从命令行运行以下命令:
gitlab-ctl stop nginx
现在端口80已经空闲,你可以启动Apache(如果尚未安装,请不要忘记安装Apache/以下说明适用于RHEL系统-根据需要进行修改,以适应Ubuntu等)。假设您是root用户:
yum install -y httpd;
systemctl start httpd;
systemctl enable httpd;
让我们编辑Gitlab配置文件,禁用nginx并告诉gitlab使用apache:
vi /etc/gitlab/gitlab.rb
将您的域名或IP添加到以下位置:
external_url 'http://git.yourdomain.com/'
查找:
更改为(不要忘记删除前面的'#'):
web_server['external_users'] = ['apache']
查找:
Change to:
nginx['enable'] = false
最后,我们需要运行“重新编译”,命令如下:
gitlab-ctl reconfigure
gitlab-ctl restart
现在我们来配置Apache。当我们安装Gitlab时,它会添加一个名为 gitlab-www 的用户组。我们需要允许 Apache 用户访问该组。以下假设您已经安装了 Apache 并且用户 apache(48)存在:
要检查 Gitlab 安装在哪个组下,可以运行:
getent group
现在让我们修改Apache的用户并将其添加到gitlab-www组中:
usermod apache --append --groups gitlab-www
现在我们需要一个Apache虚拟主机来指向gitlab安装。
在Apache的conf.d目录中添加一个虚拟主机(这将创建一个新文件):
vi /etc/httpd/conf.d/gitlab.conf
添加以下内容(根据您的需要进行微调):
<VirtualHost *:80>
ServerName git.yourdomain.com
ServerSignature Off
ProxyPreserveHost On
<Location />
Order deny,allow
Allow from all
ProxyPassReverse http://127.0.0.1:8080
ProxyPassReverse http://git.yourdomain.com/
</Location>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA]
# needed for downloading attachments
DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/httpd/access_log combined env=!dontlog
</VirtualHost>
现在重新启动Apache:
systemctl start httpd
在处理 selinux 等问题时,您可能会遇到一些问题 - 您可以将其设置为宽容模式以进行调试。
setenforce 0
希望这能对某人有所帮助!