Nginx Subdirectory Configuration #1010

Closed
opened 2026-02-04 23:23:51 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @ghost on GitHub (Jan 28, 2019).

BookStack Version: Latest
PHP Version: PHP 7.1.26
MYSQL Version: MariaDB 10.1.34
Nginx Version: 1.14.0

I did successfully install BookStack on Ubuntu 18.04 LTS and configured nginx to serve BookStack at my root domain example.local with the following config:

server {
        listen 80;
        listen [::]:80;

        server_name example.local;

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

server{
        listen 443 ssl;
        listen [::]:443 ssl;
        include snippets/self-signed.conf;
        include snippets/ssl-params.conf;

        server_name example.local;

        root /var/www/html/BookStack/public;
        index index.php index.html index.htm;

        client_max_body_size 100M;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $request_filename;
        }
}

But because I want to host multiple apps on this server I wanted to serve BookStack on a subdirectory /wiki. I changed the APP_URL parameter in the .env file and adjusted the nginx configuration file according to various suggestions using the nginx alias command. Unfortunately without success.

Is there a example Nginx configuration available similar to the Apache configuration already available for configuring BookStack on a subdirectory?

Originally created by @ghost on GitHub (Jan 28, 2019). BookStack Version: Latest PHP Version: PHP 7.1.26 MYSQL Version: MariaDB 10.1.34 Nginx Version: 1.14.0 I did successfully install BookStack on Ubuntu 18.04 LTS and configured nginx to serve BookStack at my root domain example.local with the following config: ``` server { listen 80; listen [::]:80; server_name example.local; return 301 https://$server_name$request_uri; } server{ listen 443 ssl; listen [::]:443 ssl; include snippets/self-signed.conf; include snippets/ssl-params.conf; server_name example.local; root /var/www/html/BookStack/public; index index.php index.html index.htm; client_max_body_size 100M; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $request_filename; } } ``` But because I want to host multiple apps on this server I wanted to serve BookStack on a subdirectory /wiki. I changed the APP_URL parameter in the .env file and adjusted the nginx configuration file according to various suggestions using the nginx alias command. Unfortunately without success. Is there a example Nginx configuration available similar to the Apache configuration already available for configuring BookStack on a subdirectory?
Author
Owner

@ghost commented on GitHub (Jan 28, 2019):

I got it working with the following configuration:

server {
        listen 80;
        listen [::]:80;

        server_name example.local;

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

server{
        listen 443 ssl;
        listen [::]:443 ssl;
        include snippets/self-signed.conf;
        include snippets/ssl-params.conf;

        server_name example.local;

        root /var/www/html;
        index index.php index.html index.htm;

        client_max_body_size 100M;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location /wiki {
                alias /var/www/html/BookStack/public;
                try_files $uri $uri/ @wiki;

                location ~ \.php$ {
                        include snippets/fastcgi-php.conf;
                        fastcgi_param SCRIPT_FILENAME $request_filename;
                        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
                }
        }

        location @wiki {
                rewrite /wiki/(.*)$ /wiki/index.php?/ last;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        }
}
@ghost commented on GitHub (Jan 28, 2019): I got it working with the following configuration: ``` server { listen 80; listen [::]:80; server_name example.local; return 301 https://$server_name$request_uri; } server{ listen 443 ssl; listen [::]:443 ssl; include snippets/self-signed.conf; include snippets/ssl-params.conf; server_name example.local; root /var/www/html; index index.php index.html index.htm; client_max_body_size 100M; location / { try_files $uri $uri/ /index.php?$query_string; } location /wiki { alias /var/www/html/BookStack/public; try_files $uri $uri/ @wiki; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; } } location @wiki { rewrite /wiki/(.*)$ /wiki/index.php?/ last; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1010