Positonic
Positonic

Reputation: 9411

nginx config for phpbb and laravel

I need an nginx config that will work for both Laravel and Phpbb.

I have used laravel forge to setup my digital ocean server, and it created this nginx config:

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/djembefola.org/before/*;

server {
    listen 80;
    listen [::]:80;
    server_name djembefola.org;
    root /home/forge/djembefola.org/public;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:$
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/djembefola.org/server/*;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/djembefola.org-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/djembefola.org/after/*;

The /public folder is where the front controller index.php of Laravel lives...

Also in the public folder, I have and install of phpbb at - /public/board

I am upgrading the forum, and as such I need to rum the phpbb installer, which resides at:

localhost/board/install,

which then calls:

localhost/board/install/app.php/update

The above url is then giving a 404 error.

I have read elsewhere that this is because Nginx needs to be configured correctly in order to run the installer.

The sample Nginx config for phpbb is listed here.

So I need to merge these somehow, but so far my attempts have failed.

I tried adding :

location /board/ {
    rewrite ^(.*)$ /app.php/$1 last;
}

to the existing laravel nginx file, but that fails. I am aware that I need to put it in the right place in the nginx config, but I fear I'm probably overlooking something else, as I am guessing a bit here...

Can anyone help please?

Upvotes: 0

Views: 632

Answers (1)

jsonUK
jsonUK

Reputation: 353

Based off the example config, you can nest required rules within a block wrap (just like they have done with the /install/ directory). eg:

location /board/ {
    try_files $uri $uri/ @rewriteapp;    

    # Deny access to internal phpbb files.
    location ~ /(config\.php|common\.php|cache|files|images/avatars/upload|includes|(?<!ext/)phpbb|store|vendor) {
        deny all;
        # deny was ignored before 0.8.40 for connections over IPv6.
        # Use internal directive to prohibit access on older versions.
        internal;
    }

    # Pass the php scripts to fastcgi server specified in upstream declaration.
    location ~ \.php(/|$) {
        # Unmodified fastcgi_params from nginx distribution.
        include fastcgi_params;
        # Necessary for php.
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        try_files $uri $uri/ /board/app.php$is_args$args;
        fastcgi_pass php;
    }
}

location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
}

Note that @rewriteapp is outside the block wrap. Nginx will complain if you try to place it inside.

Just amend the paths to match your directory.

Upvotes: 1

Related Questions