FreeBSD, Jail, Nginx, Nextcloud : I Need Help!

Hello from France !

I need your help to achieve my configuration qhat I’m trying to test : I want to securize my server with working with Jail.

I have :

  • a FreeBSD Host 13.1 (ip=192.168.1.120) with an nginx ;
  • a jail (ip=10.7.16.101) with nginx, php-fpm for Nextcloud 26 in a subdirectory /nextcloud ;

My problem is that the Nextcloud don’t works normaly…

This is the config file of the nginx of the host :

worker_processes 1;

events {
worker_connections 1024;
}

http {
include /usr/local/etc/nginx/mime.types;
default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

server {
listen 80;
server_name localhost;

include /usr/local/etc/nginx/mime.types;

location / {
root /usr/local/www/nginx;
index index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}

location /nextcloud
{
proxy_set_header Host $host; #gp
proxy_set_header X-Real-IP $remote_addr;#gp
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Server $server_name;
proxy_pass http://10.7.16.101;
}
}
}

Click to expand…
This is the config file of the nginx of the jail :

worker_processes 1;

events {
worker_connections 1024;
}

http {
include /usr/local/etc/nginx/mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

upstream php-handler {
server 127.0.0.1:9000;
}

map $arg_v $asset_immutable {
“” “”;
default “immutable”;
}

server {
listen 80;
server_name 10.7.16.101;

root /usr/local/www/nextcloud;

server_tokens off;
client_max_body_size 512M;
client_body_timeout 300s;
fastcgi_buffers 64 4K;
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml text/javascript application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

client_body_buffer_size 512k;
fastcgi_hide_header X-Powered-By;

include /usr/local/etc/nginx/mime.types;
types {
text/javascript js mjs;
}

index index.php index.html /index.php$request_uri;

location = / {
if ( $http_user_agent ~ ^DavClnt ) {
return 302 /remote.php/webdav/$is_args$args;
}
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location ^~ /.well-known {
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }

location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
location /.well-known/pki-validation { try_files $uri $uri/ =404; }

return 301 /index.php$request_uri;
}

location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
location ~ ^/(?:.|autotest|occ|issue|indie|db_|console) { return 404; }

location ~ .php(?:$|/) {
rewrite ^/(?!index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|oc[ms]-provider/.+|.+/richdocumentscode/proxy) /index.php$request_uri;

fastcgi_split_path_info ^(.+?.php)(/.*)$;
set $path_info $fastcgi_path_info;

try_files $fastcgi_script_name =404;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;

fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
fastcgi_param front_controller_active true; # Enable pretty urls
fastcgi_pass php-handler;

fastcgi_intercept_errors on;
fastcgi_request_buffering off;

fastcgi_max_temp_file_size 0;
}

Serve static files

location ~ .(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control “public, max-age=15778463, $asset_immutable”;
access_log off; # Optional: Don’t log access to assets

location ~ .wasm$ {
default_type application/wasm;
}
}

location ~ .woff2?$ {
try_files $uri /index.php$request_uri;
expires 7d; # Cache-Control policy borrowed from .htaccess
access_log off; # Optional: Don’t log access to assets
}

Rule borrowed from .htaccess

location /remote {
return 301 /remote.php$request_uri;
}

location / {
try_files $uri $uri/ /index.php$request_uri;
}

}
}

Click to expand…

This is the config file of Nextcloud :

<?php $CONFIG = array ( 'overwritehost' => '192.168.1.120', 'overwritewebroot' => '/nextcloud', 'trusted_domains' => array ( 0 => '10.7.16.101', 2 => '192.168.1.120', ), 'overwrite.cli.url' => 'http://192.168.1.120/nextcloud', 'apps_paths' => array ( 0 => array ( 'path' => '/usr/local/www/nextcloud/apps', 'url' => '/apps', 'writable' => true, ), 1 => array ( 'path' => '/usr/local/www/nextcloud/apps-pkg', 'url' => '/apps-pkg', 'writable' => false, ), ), 'logfile' => '/var/log/nextcloud/nextcloud.log', 'memcache.local' => '\\OC\\Memcache\\APCu', 'instanceid' => 'oc1lgk4z97b8', ); Click to expand...

When I try to access 192.168.1.120/nextcloud, I get some errors as the file shows.

I don’t know how to solve the errors that appear…

Any idea/Advice ?

Many thanks in advance !

More information about this problem :

I’have added a rule to firewall to forward port 80 directly to the jail => Same errors exactly…

Any idea ?

Well, after many test, i’ve commented out the try_files in :

    # Serve static files
    location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463, $asset_immutable";
        access_log off;     # Optional: Don't log access to assets

        location ~ \.wasm$ {
            default_type application/wasm;
        }
    }

So, I got some 404s :

Similar issue here, The server was running correctly.

Then next to an upgrade (Nginx, php, nextcloud ?) it sounds that css file are not served anymore.

I changed the static file match location this way:

  # Serve static files
    location ~* \.(?:css) {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463, $asset_immutable";
        access_log off;     # Optional: Don't log access to assets
        default_type text/css;
 
}

    location ~* \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463, $asset_immutable";
        access_log off;     # Optional: Don't log access to assets

        location ~ \.wasm$ {
            default_type application/wasm;
        }
    }

It’s better except that the icons/pictures are still missing.