Nginx config #258

Closed
opened 2026-02-04 18:07:43 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @TribuneX on GitHub (Feb 5, 2017).

PHP Version: PHP 7.0.14-2
MySQL Version: 5.5.54-0+deb8u1

I am having issues running BookStack with nginx, since I am running mutliple sites on my nginx server. Therefore, I can`t set root to /var/www/bookstack/public as suggested.

BookStack does not seem to work properly without root set to /var/www/bookstack/public

Instead my nginx config (extract) looks like follows:

server {
	listen 80;
	listen [::]:80 ipv6only=on;
	listen 443 ssl http2;
	listen [::]:443 ipv6only=on ssl http2;

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

	server_name mydomain.net;
	
	charset utf-8;


  	# Adding the cache control header for js and css files
  	# Make sure it is BELOW the location ~ \.php(?:$|/) { block
  	location ~* \.(?:css|js)$ {
    	add_header Cache-Control "public, max-age=7200";
    	# Add headers to serve security related headers
    	add_header Strict-Transport-Security "max-age=15768000; 		includeSubDomains; preload;";
    	add_header X-Content-Type-Options nosniff;
    	add_header X-Frame-Options "SAMEORIGIN";
    	add_header X-XSS-Protection "1; mode=block";
    	add_header X-Robots-Tag none;
    	# Optional: Don't log access to assets
    	access_log off;
  	}

  	location ~ ^(.+\.php)(.*) {
		try_files $fastcgi_script_name =404;
		fastcgi_split_path_info ^(.+\.php)(.*)$;

		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
		fastcgi_param  PATH_INFO        $fastcgi_path_info;
		fastcgi_index index.php;
		include fastcgi_params;
	}

	
	location ~ \.php(?:$|/) {
    	fastcgi_split_path_info ^(.+\.php)(/.+)$;
    	include fastcgi_params;
    	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    	fastcgi_param PATH_INFO $fastcgi_path_info;
    	fastcgi_param HTTPS on;
    	fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    	fastcgi_intercept_errors on;
  	}

	location / {
               try_files $uri $uri/ /index.html;		
    }

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

I can access the BookStack startpage, but trying to access e.g. "Books" gives me an 404 with the following message in my nginx error.log:

2017/02/05 13:16:50 [error] 4281#4281: *3 open() "/var/www/bookstack/public/translations.js" failed
(2: No such file or directory), client: 192.168.178.29, server: mydomain.net, request: "GET
/bookstack/public/translations.js HTTP/2.0", host: "mydomain.net", referrer: "https://mydomain.net/bookstack/public/"

Does someone have a working nginx config, where the root is not changed for every location?

Originally created by @TribuneX on GitHub (Feb 5, 2017). PHP Version: PHP 7.0.14-2 MySQL Version: 5.5.54-0+deb8u1 I am having issues running BookStack with nginx, since I am running mutliple sites on my nginx server. Therefore, I can`t set root to /var/www/bookstack/public as suggested. BookStack does not seem to work properly without root set to /var/www/bookstack/public Instead my nginx config (extract) looks like follows: ``` server { listen 80; listen [::]:80 ipv6only=on; listen 443 ssl http2; listen [::]:443 ipv6only=on ssl http2; root /var/www; index index.html index.htm index.php; server_name mydomain.net; charset utf-8; # Adding the cache control header for js and css files # Make sure it is BELOW the location ~ \.php(?:$|/) { block location ~* \.(?:css|js)$ { add_header Cache-Control "public, max-age=7200"; # Add headers to serve security related headers add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; add_header X-Content-Type-Options nosniff; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; # Optional: Don't log access to assets access_log off; } location ~ ^(.+\.php)(.*) { try_files $fastcgi_script_name =404; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_index index.php; include fastcgi_params; } location ~ \.php(?:$|/) { fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param HTTPS on; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_intercept_errors on; } location / { try_files $uri $uri/ /index.html; } location /bookstack/ { try_files $uri $uri/ /index.php?$query_string; } ``` I can access the BookStack startpage, but trying to access e.g. "Books" gives me an 404 with the following message in my nginx error.log: ``` 2017/02/05 13:16:50 [error] 4281#4281: *3 open() "/var/www/bookstack/public/translations.js" failed (2: No such file or directory), client: 192.168.178.29, server: mydomain.net, request: "GET /bookstack/public/translations.js HTTP/2.0", host: "mydomain.net", referrer: "https://mydomain.net/bookstack/public/" ``` Does someone have a working nginx config, where the root is not changed for every location?
Author
Owner

@TribuneX commented on GitHub (Feb 6, 2017):

I moved BookStack to an additional domain on my nginx server. So I was able to follow the installation guide.

@TribuneX commented on GitHub (Feb 6, 2017): I moved BookStack to an additional domain on my nginx server. So I was able to follow the installation guide.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#258