Nginix conf intructions to OPNSense UI

Started by baz, January 31, 2023, 09:32:55 AM

Previous topic - Next topic
Hello,

I am setting up a Seafile instance to run through the nginx plugin in OPNSense. Seafile provides an example nginx conf to emulate, but I am having trouble getting it right using the OPNSense UI and was wondering if someone could help. The example conf looks like this:


log_format seafileformat '$http_x_forwarded_for $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time';

server {
    listen 80;
    server_name seafile.example.com;

    proxy_set_header X-Forwarded-For $remote_addr;

    location / {
         proxy_pass         http://127.0.0.1:8000;
         proxy_set_header   Host $host;
         proxy_set_header   X-Real-IP $remote_addr;
         proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header   X-Forwarded-Host $server_name;
         proxy_read_timeout  1200s;

         # used for view/edit office file via Office Online Server
         client_max_body_size 0;

         access_log      /var/log/nginx/seahub.access.log seafileformat;
         error_log       /var/log/nginx/seahub.error.log;
    }

    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        client_max_body_size 0;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_send_timeout  36000s;

        send_timeout  36000s;

        access_log      /var/log/nginx/seafhttp.access.log seafileformat;
        error_log       /var/log/nginx/seafhttp.error.log;
    }

    location /media {
        root /opt/seafile/seafile-server-latest/seahub;
    }
}


Specifically I am unsure about how to implement the "proxy_pass" in "location" "/seafhttp":



I already have an "upstream" and "upstream server" defined for port 8000 to satisfy the first "location":




Should I create a second "upstream" and "upstream server" to handle port 8082?



Do I then add a "location" for it:



And associate that location with the existing "HTTP Server" already created:



Or perhaps create a separate "HTTP Server" for it?

I also have a question about the "rewrite" code:



I created the following "URL Rewrite":



Then I selected it in both, the "HTTP Server", and the "Location" for "/seafhttp" - is that right?

Thanks for any help on part or all of this.



Hi!
opnsense nginx plugin uses upstream module to pass requests (https://nginx.org/en/docs/http/ngx_http_upstream_module.html), therefore it is not possible to get an exact replica of the example config - part of the parameters will be determined in the upstream context.
QuoteShould I create a second "upstream" and "upstream server" to handle port 8082?
yes
QuoteDo I then add a "location" for it:
yes
QuoteAnd associate that location with the existing "HTTP Server" already created
yess
QuoteOr perhaps create
no  ;)
QuoteI created the following "URL Rewrite
looks fine
QuoteThen I selected it in both, the "HTTP Server", and the "Location" for "/seafhttp" - is that right?
should be added to Location only

Thanks a lot for your helpful response! Should the second location look like this: