Skip to content

NGINX server config

Robert Isoski edited this page Jan 26, 2022 · 19 revisions

Paste the below code into your NGINX server config file /etc/nginx/nginx.conf or the config file in /etc/nginx/site-available/wondercms.conf (and enable it with a symlink in the site-enabled folder).

Replace the server_name with your actual domain and the root path with your actual path where WonderCMS is installed.

server {
        listen 80;
        # adapt to your server name
        server_name www.wonder-example.com;
        # adapt the path
        root /var/www/wondercms;
        index index.php;
        # prevent directory listing
        autoindex off;

        # rewrite url to make it pretty
        location / {
            try_files $uri $uri/ @rewrite;
        }
            location @rewrite {
            rewrite ^/(.+)$ /index.php?page=$1 last;
        }

        # prevent access to database.js
        location ~ database.js {
            return 403;
        }

        location ~ cache.json {
            return 403;
        }

        # use php-fpm for dealing with php files
        location ~ \.php(/|$) {
            # this could also be called fastcgi_params depending on your distribution
            include fastcgi.conf;
            # using unix socket
            fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
            # uncomment (and comment the one above) if you are using the TCP port 9000 for php-fpm
            # fastcgi_pass 127.0.0.1:9000;
        }
    }

The code above replicates Apache's htaccess functionality with the power of your NGINX server config. Since NGINX doesn't have the "traditional" htaccess file, this is necessary to make WonderCMS work properly.


NOTE: The code above is required to deny access to database.js, cache.json and make clean URL's which are SEO friendly.


Thanks for @NicolasCARPi for providing a neat solution!

Clone this wiki locally