关于apache:Apache-做反向代理

6次阅读

共计 834 个字符,预计需要花费 3 分钟才能阅读完成。

昨天在百度云服务器上安装了 gitea,应用起来还不错,还有我的项目看板性能。gitea 默认通过 3000 端口拜访,而我的服务器上安装的是 apache,所以就思考应用 apache 来做反向代理。

首先筹备好域名,git.example.cn

我的服务器上装的是 ubuntu 20.04,开启 apache 的代理模块

cd /etc/apache2
sudo a2enmod proxy proxy_balancer proxy_http

这里用到了 a2enmod,这个工具能够给 apache 减少失效模块,成果其实就是在 mods-enabled 目录建设软链接,指向 mods-available 目录下的模块。如果要让模块生效,则应用 a2dismod。

好了,回归正题,前边开启了 apache 的代理相干模块,下边就来配置域名了。

在 sites-available 目录下新建一个配置文件,如下:

cd ./sites-available
sudo cp 000-default.conf git.example.cn.conf

编辑配置文件

sudo vim git.example.cn.conf
<VirtualHost *:80>  ProxyPreserveHost On
  ServerName git.example.cn
  ProxyPass / http://127.0.0.1:3000/
  ProxyPassReverse / http://127.0.0.1:3000/
  <Proxy *>       Order Deny,Allow
Allow from all
  </Proxy></VirtualHost>

配置文件编辑完之后,建设软链接

cd ../sites-enabled
sudo ln -s ../sites-available/git.example.cn.conf

而后重启 apache 服务

sudo systemctl restart apache2.service

至此,咱们就能够应用 git.example.cn 这个域名来拜访 gitea 了。

正文完
 0