# Proxy Setup

## Setting up LANraragi behind a proxy (reverse proxy setup)

A common post-install setup is to make requests to the app transit through a gateway server such as Apache or nginx.\
If you do so, please note that archive uploads through LRR will likely **not work out of the box** due to maximum sizes on uploads those servers can enforce. The example below is for nginx:

```
http {
    client_max_body_size 0;   <----------------------- This line here
}

server {
    listen 80;

    server_name lanraragi.[REDACTED].net;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    index index.php index.html index.htm;
    server_name lanraragi.[REDACTED].net;

    client_max_body_size 0;           <---------- And this line here to disable upload limit
    proxy_max_temp_file_size 0;       <---------- And this line here to support large downloads

    # Cert Stuff Omitted

    location / {
        proxy_pass http://0.0.0.0:3000;
        proxy_http_version 1.1;
        <----- The two following lines are needed for batch tagger support with SSL ----->
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection $connection_upgrade;
    }
}
```

By default, LRR runs at the server root,\
e.g. <https://lanraragi.example.com/>. You may wish to instead run it under a\
specific URL subdirectory, e.g. <https://example.com/lanraragi/>.

This configuration requires that the reverse proxy be configured to strip the\
URL prefix from requests before forwarding it. For nginx, this is:

```
server {
    # ...

    location /lanraragi {
        rewrite ^/lanraragi(.*)$ $1 last;
        # ...rest of the block here
    }
}
```

After this is done, you need to configure LANraragi to use the new prefix. This\
is set under `lrr.conf` in the app root directory. Set the variable`base_url_path` as desired, e.g.:

```
{
  # other directives...
  base_url_path => "/lanraragi",
}
```

Make sure to restart the server after editing `lrr.conf`. This will make the app\
available under `/lanraragi`.

## Setting up LANraragi to use a proxy for outbound network requests

This is a less common scenario, but you might want to have downloads or metadata requests to external services go through a proxy, in case said external services are blocked by your friendly local totalitarian regime.

LANraragi runs on top of the Mojolicious web server, which has [built-in](https://docs.mojolicious.org/Mojo/UserAgent/Proxy#detect) support for proxifying external requests.

To enable automatic proxy detection, the `MOJO_PROXY` environment variable must be set to 1 on your machine: This is enabled by default on Docker builds.\
Once said detection enabled, environment variables `HTTP_PROXY, http_proxy, HTTPS_PROXY, https_proxy, NO_PROXY` and `no_proxy` will be checked for proxy information.

Here's an example for a Docker-compose setup:

```
---
version: "2.1"
services:
  lanraragi:
    image: difegue/lanraragi:latest
    container_name: lanraragi
    environment:
      - http_proxy=http://192.168.10.186:1082
      - https_proxy=http://192.168.10.186:1082
    volumes:
      - [database]:/home/koyomi/lanraragi/database
      - [content]:/home/koyomi/lanraragi/content
    ports:
      - 7070:3000
    restart: unless-stopped
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sugoi.gitbook.io/lanraragi/dev/advanced-usage/proxy-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
