【问题标题】:gitea using a normal user and httpsgitea 使用普通用户和 https
【发布时间】:2020-01-30 15:33:37
【问题描述】:

我正在尝试将 gitea 设置为将 https 与我从letsencrypt 获得的证书一起以普通用户身份运行服务。

我已经使用普通用户git 在端口 80 上使用 http 并使用 iptables 将端口 80 重定向到端口 3000。

另外我已经让它在端口 3000 上使用 https 重定向到端口 3080。

但我不知道如何配置它(可能与 iptables 一起),以便对端口 80 的请求重定向到适当的端口(3000?3080?)。

我以 root 身份使用此 iptables 命令将端口 80 重定向到端口 3000:

# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000

这是我的 HTTP 配置的相关部分

RUN_USER         = git

LOCAL_ROOT_URL   = http://localhost:3000/
DOMAIN           = example
HTTP_PORT        = 80
ROOT_URL         = http://example.com

这是我在端口 3000 上重定向到端口 3080 的 HTTP 配置

RUN_USER            = git

PROTOCOL            = https
LOCAL_ROOT_URL      = https://localhost:3000/
DOMAIN              = example.com
HTTP_PORT           = 3000
REDIRECT_OTHER_PORT = true
PORT_TO_REDIRECT    = 3080
ROOT_URL            = https://example.com
CERT_FILE           = /etc/letsencrypt/live/example.com/fullchain.pem
KEY_FILE            = /etc/letsencrypt/live/example.com/privkey.pem

使用此配置,我可以访问https://example.com:3000,它工作正常,但如果我访问https://example.com:3080,我会得到一个Secure Connection FailedError code: SSL_ERROR_RX_RECORD_TOO_LONG

我尝试使用 iptables 将端口 80 重定向到端口 3080,但没有成功。

您能帮我设置一下,以便我可以在端口 80 中以普通用户身份运行该服务,以便人们可以通过 https://example.com 访问它吗? (也许事先使用 iptables 作为 root 重定向一些端口)提前谢谢

【问题讨论】:

    标签: ssl https iptables gitea


    【解决方案1】:

    letsencrypt api 包含在 gitea 中。要使用 docker-compose 设置 gitea 并进行加密,只需编辑您的 [server] 配置,如下所示:

    ....
    [server]
    APP_DATA_PATH    = /data/gitea
    DOMAIN           = example.com
    SSH_DOMAIN       = example.com
    HTTP_PORT        = 443
    ROOT_URL         = http://example.com
    PROTOCOL=https
    ENABLE_LETSENCRYPT=true
    LETSENCRYPT_ACCEPTTOS=true
    LETSENCRYPT_DIRECTORY=https
    LETSENCRYPT_EMAIL=info@foo.com
    .....
    

    您的 docker-compose.yaml 端口配置将如下所示:

      server:
        image: gitea/gitea:1.13.2
        container_name: gitea
        ports:
          - "443:443"
          - "222:22"
    ....
    

    【讨论】:

      【解决方案2】:

      如果其他人需要它,最终的配置文件就是这个,它将http请求重定向到https。

      我按照 ptman 的建议使用了 # setcap cap_net_bind_service=+ep /path/to/binary/gitea

      RUN_USER            = git
      
      [server]
      PROTOCOL            = https
      DOMAIN              = example.com
      HTTP_PORT           = 443
      REDIRECT_OTHER_PORT = true
      CERT_FILE           = /etc/letsencrypt/live/example.com/fullchain.pem
      KEY_FILE            = /etc/letsencrypt/live/example.com/privkey.pem
      SSH_DOMAIN          = example.com
      DISABLE_SSH         = false
      SSH_PORT            = 22
      OFFLINE_MODE        = false
      

      【讨论】:

        【解决方案3】:

        HTTPS 的端口是 443。大多数人会通过使用反向代理而不是 iptables 来解决这个问题。

        Gitea 可以自己处理letsencrypt。方法如下:

        [server]
        PROTOCOL=https
        DOMAIN=git.example.com
        ENABLE_LETSENCRYPT=true
        LETSENCRYPT_ACCEPTTOS=true
        LETSENCRYPT_DIRECTORY=https
        LETSENCRYPT_EMAIL=email@example.com
        

        取自:https://docs.gitea.io/en-us/https-setup/

        【讨论】:

        • 这要求普通用户能够打开端口80,我的问题是关于不必以root身份运行服务
        • setcap cap_net_bind_service=+ep /path/to/binary/gitea
        猜你喜欢
        • 1970-01-01
        • 2013-09-06
        • 1970-01-01
        • 2016-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-27
        相关资源
        最近更新 更多