侧边栏壁纸
博主头像
进一步,海阔天空 博主等级

进一步,海阔天空

  • 累计撰写 140 篇文章
  • 累计创建 19 个标签
  • 累计收到 7 条评论

目 录CONTENT

文章目录

Apache2整合Gitea配置https访问

海阔天空
2022-05-28 / 0 评论 / 0 点赞 / 330 阅读 / 0 字

如果您的web服务器是Apache,本文介绍如何通过Apache配置https证书,并访问后端的gitea服务。

确认服务器环境

  • 首选确认你的服务器环境,如果你直接通过gitea对外发布站点,而没有通过Apache或Nginx做转发,请参考我的另一篇文章docker安装gitea并启用https访问

申请证书

  • 到freessl.cn申请一个免费证书
    image-1654585130317
    选项如下:
    image-1654585145433
    得到的fileauth.text文件,按照提示放到站点的.well-known/pki-validation目录下。然后点击验证等待验证通过。验证通过后,就会得到一个证书和key,把内容分别存放在ca_bundle.crt,git.xxx.com.crt,git.xxx.com_key.key文件中。
    申请证书

配置https证书

  • 打开Apache的conf\extra\httpd-ssl.conf,配置证书
<VirtualHost *:443>
    ServerName git.xxx.com
	SSLEngine on
    SSLCertificateFile E:/Apache24/conf/extra/git-xxx-com/git.xxx.com.crt
    SSLCertificateKeyFile E:/Apache24/conf/extra/git-xxx-com/git.xxx.xom_key.key
    SSLCertificateChainFile E:/Apache24/conf/extra/git-xxx-com/ca_bundle.crt
	ServerAdmin admin@163.com
	DirectoryIndex index.html index.jsp index.htm index.php
	ProxyPass / http://192.168.*.*:10080/ 
    ProxyPassReverse / http://192.168.*.*:10080/
</VirtualHost>  

注意,我们这里,gitea是通过docker安装在192.168.*.*这台服务器上的,开放的端口是10080。

配置http转发到https

  • 打开Apache的conf/httpd.conf文件,配置所有的http请求都转发到https即可。
<VirtualHost *:80>
	ServerName git.xxx.com
	ServerAdmin admin@163.com
	
    #转发所有的http请求到https
	RewriteEngine on
    RewriteCond   %{HTTPS} !=on
    RewriteRule   ^(.*)  https://%{SERVER_NAME}$1 [L,R]
	
	DirectoryIndex index.html index.jsp index.htm index.php
	ProxyPass / http://192.168.*.*:10080/ 
    ProxyPassReverse / http://192.168.*.*:10080/	
</VirtualHost>
0

评论区