2018-05-23 13:21:17 +08:00
---
date: "2018-05-22T11:00:00+00:00"
title: "Usage: Reverse Proxies"
slug: "reverse-proxies"
weight: 17
toc: true
draft: false
menu:
sidebar:
parent: "usage"
name: "Reverse Proxies"
weight: 16
identifier: "reverse-proxies"
---
## Using Nginx as a reverse proxy
2019-03-10 05:15:45 +08:00
If you want Nginx to serve your Gitea instance, you can the following `server` section inside the `http` section of `nginx.conf` :
2018-05-23 13:21:17 +08:00
```
server {
listen 80;
server_name git.example.com;
location / {
proxy_pass http://localhost:3000;
}
}
```
2019-03-10 05:15:45 +08:00
## Using Nginx with a sub-path as a reverse proxy
2018-05-23 13:21:17 +08:00
In case you already have a site, and you want Gitea to share the domain name, you can setup Nginx to serve Gitea under a sub-path by adding the following `server` section inside the `http` section of `nginx.conf` :
```
server {
listen 80;
server_name git.example.com;
location /git/ { # Note: Trailing slash
proxy_pass http://localhost:3000/; # Note: Trailing slash
}
}
```
Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.
## Using Apache HTTPD as a reverse proxy
2019-03-10 05:15:45 +08:00
If you want Apache HTTPD to serve your Gitea instance, you can add the following to your Apache HTTPD configuration (usually located at `/etc/apache2/httpd.conf` in Ubuntu):
2018-05-23 13:21:17 +08:00
```
< VirtualHost * :80 >
...
ProxyPreserveHost On
ProxyRequests off
2019-07-21 02:44:53 +08:00
AllowEncodedSlashes NoDecode
ProxyPass / http://localhost:3000/ nocanon
2018-05-23 13:21:17 +08:00
ProxyPassReverse / http://localhost:3000/
< / VirtualHost >
```
Note: The following Apache HTTPD mods must be enabled: `proxy` , `proxy_http`
2019-03-10 05:15:45 +08:00
## Using Apache HTTPD with a sub-path as a reverse proxy
2018-05-23 13:21:17 +08:00
In case you already have a site, and you want Gitea to share the domain name, you can setup Apache HTTPD to serve Gitea under a sub-path by adding the following to you Apache HTTPD configuration (usually located at `/etc/apache2/httpd.conf` in Ubuntu):
```
< VirtualHost * :80 >
...
< Proxy * >
Order allow,deny
Allow from all
2019-07-21 02:44:53 +08:00
AllowEncodedSlashes NoDecode
2018-05-23 13:21:17 +08:00
< / Proxy >
2019-07-21 02:44:53 +08:00
ProxyPass /git http://localhost:3000 nocanon # Note: no trailing slash after either /git or port
2018-05-23 13:21:17 +08:00
ProxyPassReverse /git http://localhost:3000 # Note: no trailing slash after either /git or port
< / VirtualHost >
```
Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.
Note: The following Apache HTTPD mods must be enabled: `proxy` , `proxy_http`
2018-10-18 02:19:04 +08:00
## Using Caddy as a reverse proxy
2018-05-23 13:21:17 +08:00
2019-03-10 05:15:45 +08:00
If you want Caddy to serve your Gitea instance, you can add the following server block to your Caddyfile:
2018-05-23 13:21:17 +08:00
```
git.example.com {
proxy / http://localhost:3000
}
```
2019-03-10 05:15:45 +08:00
## Using Caddy with a sub-path as a reverse proxy
2018-05-23 13:21:17 +08:00
2019-03-10 05:15:45 +08:00
In case you already have a site, and you want Gitea to share the domain name, you can setup Caddy to serve Gitea under a sub-path by adding the following to your server block in your Caddyfile:
2018-05-23 13:21:17 +08:00
```
git.example.com {
proxy /git/ http://localhost:3000 # Note: Trailing Slash after /git/
}
```
2018-05-24 08:24:04 +08:00
Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.