Nginx Library

A repository of Nginx-related articles

Nginx configuration for phpBB

I had previously written an article about converting phpBB’s default htaccess rules to Nginx. Here I’ll share a full-blown Nginx configuration file for serving a phpBB forum.

This configuration file :

  • Redirects www sub domain to the bare domain along with any parked domains.
  • Prevents external access to files and directories like config.php, avatar upload directory, etc.
  • Sets proper Expires header for images.
server {
    listen   [::]:80;
    server_name *;
    rewrite ^$request_uri? permanent;

server {
    listen   [::]:80;
    root   /var/www/;
    index  index.php index.html index.htm;
    access_log  /var/logs/;

    location ~ /(config\.php|common\.php|cache|files|images/avatars/upload|includes|store) {
        deny all;
        return 403;

    location ~* \.(gif|jpe?g|png|css)$ {
        expires   30d;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass   unix:/tmp/php.socket;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
If you find this article helpful, please consider making a donation.