Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

https-support.md 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ---
  2. date: "2018-06-02T11:00:00+02:00"
  3. title: "Usage: HTTPS setup"
  4. slug: "https-setup"
  5. weight: 12
  6. toc: false
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "usage"
  11. name: "HTTPS setup"
  12. weight: 12
  13. identifier: "https-setup"
  14. ---
  15. # HTTPS setup to encrypt connections to Gitea
  16. **Table of Contents**
  17. {{< toc >}}
  18. ## Using the built-in server
  19. Before you enable HTTPS, make sure that you have valid SSL/TLS certificates.
  20. You could use self-generated certificates for evaluation and testing. Please run `gitea cert --host [HOST]` to generate a self signed certificate.
  21. If you are using Apache or nginx on the server, it's recommended to check the [reverse proxy guide]({{< relref "doc/usage/reverse-proxies.en-us.md" >}}).
  22. To use Gitea's built-in HTTPS support, you must change your `app.ini` file:
  23. ```ini
  24. [server]
  25. PROTOCOL = https
  26. ROOT_URL = https://git.example.com:3000/
  27. HTTP_PORT = 3000
  28. CERT_FILE = cert.pem
  29. KEY_FILE = key.pem
  30. ```
  31. Note that if your certificate is signed by a third party certificate authority (i.e. not self-signed), then cert.pem should contain the certificate chain. The server certificate must be the first entry in cert.pem, followed by the intermediaries in order (if any). The root certificate does not have to be included because the connecting client must already have it in order to estalbish the trust relationship.
  32. To learn more about the config values, please checkout the [Config Cheat Sheet](../config-cheat-sheet#server-server).
  33. For the `CERT_FILE` or `KEY_FILE` field, the file path is relative to the `GITEA_CUSTOM` environment variable when it is a relative path. It can be an absolute path as well.
  34. ### Setting up HTTP redirection
  35. The Gitea server is only able to listen to one port; to redirect HTTP requests to the HTTPS port, you will need to enable the HTTP redirection service:
  36. ```ini
  37. [server]
  38. REDIRECT_OTHER_PORT = true
  39. ; Port the redirection service should listen on
  40. PORT_TO_REDIRECT = 3080
  41. ```
  42. If you are using Docker, make sure that this port is configured in your `docker-compose.yml` file.
  43. ## Using ACME (Default: Let's Encrypt)
  44. [ACME](https://tools.ietf.org/html/rfc8555) is a Certificate Authority standard protocol that allows you to automatically request and renew SSL/TLS certificates. [Let's Encrypt](https://letsencrypt.org/) is a free publicly trusted Certificate Authority server using this standard. Only `HTTP-01` and `TLS-ALPN-01` challenges are implemented. In order for ACME challenges to pass and verify your domain ownership, external traffic to the gitea domain on port `80` (`HTTP-01`) or port `443` (`TLS-ALPN-01`) has to be served by the gitea instance. Setting up [HTTP redirection](#setting-up-http-redirection) and port-forwards might be needed for external traffic to route correctly. Normal traffic to port `80` will otherwise be automatically redirected to HTTPS. **You must consent** to the ACME provider's terms of service (default Let's Encrypt's [terms of service](https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf)).
  45. Minimum setup using the default Let's Encrypt:
  46. ```ini
  47. [server]
  48. PROTOCOL=https
  49. DOMAIN=git.example.com
  50. ENABLE_ACME=true
  51. ACME_ACCEPTTOS=true
  52. ACME_DIRECTORY=https
  53. ;; Email can be omitted here and provided manually at first run, after which it is cached
  54. ACME_EMAIL=email@example.com
  55. ```
  56. Minimumg setup using a [smallstep CA](https://github.com/smallstep/certificates), refer to [their tutorial](https://smallstep.com/docs/tutorials/acme-challenge) for more information.
  57. ```ini
  58. [server]
  59. PROTOCOL=https
  60. DOMAIN=git.example.com
  61. ENABLE_ACME=true
  62. ACME_ACCEPTTOS=true
  63. ACME_URL=https://ca.example.com/acme/acme/directory
  64. ;; Can be omitted if using the system's trust is preferred
  65. ;ACME_CA_ROOT=/path/to/root_ca.crt
  66. ACME_DIRECTORY=https
  67. ACME_EMAIL=email@example.com
  68. ```
  69. To learn more about the config values, please checkout the [Config Cheat Sheet](../config-cheat-sheet#server-server).
  70. ## Using a reverse proxy
  71. Setup up your reverse proxy as shown in the [reverse proxy guide](../reverse-proxies).
  72. After that, enable HTTPS by following one of these guides:
  73. - [nginx](https://nginx.org/en/docs/http/configuring_https_servers.html)
  74. - [apache2/httpd](https://httpd.apache.org/docs/2.4/ssl/ssl_howto.html)
  75. - [caddy](https://caddyserver.com/docs/tls)
  76. Note: Enabling HTTPS only at the proxy level is referred as [TLS Termination Proxy](https://en.wikipedia.org/wiki/TLS_termination_proxy). The proxy server accepts incoming TLS connections, decrypts the contents, and passes the now unencrypted contents to Gitea. This is normally fine as long as both the proxy and Gitea instances are either on the same machine, or on different machines within private network (with the proxy is exposed to outside network). If your Gitea instance is separated from your proxy over a public network, or if you want full end-to-end encryption, you can also [enable HTTPS support directly in Gitea using built-in server](#using-the-built-in-server) and forward the connections over HTTPS instead.