WikiDocs icon indicating copy to clipboard operation
WikiDocs copied to clipboard

NGINX config

Open brentonv opened this issue 2 years ago • 4 comments

Can someone please post a working NGINX config for rewrite

Thank you

brentonv avatar Jul 11 '22 13:07 brentonv

My apologies, I just noticed this duplicate in closed issues

nginx config file #22

Although, I'm finding it doesn't work so hopefully someone can post a better solution..

brentonv avatar Jul 14 '22 06:07 brentonv

Hi @brentonv, if you confirm that it works correctly I will include it!

Zavy86 avatar Jul 14 '22 06:07 Zavy86

Sorry @Zavy86 I was just testing it now and edited my comment ^

I'll do some more thorough testing again and let you know what I can work out, as your project is brilliant and I would really like a solution to this.

Thank you

brentonv avatar Jul 14 '22 06:07 brentonv

Sorry, but I have no way to test nginx, I use apache, I hope some other user can help you.. If you can solve the problem I would appreciate if you tell us the solution!

Zavy86 avatar Jul 14 '22 07:07 Zavy86

hi, in the next version i will try to build also a nginx version ith docker. @brentonv are you using docker or a local nginx environment?

Zavy86 avatar May 04 '23 06:05 Zavy86

fix by @leomoon

Zavy86 avatar May 13 '23 08:05 Zavy86

@brentonv are you using docker or a local nginx environment?

Sorry for the delay, unfortunately I could not get this config to work with my local webserver environment

brentonv avatar May 18 '23 09:05 brentonv

I'll paste my full config soon.

Also remember if wikidocs is at root, location should change to /

leomoon avatar May 18 '23 10:05 leomoon

So this configuration works on a Linux with PHP and Nginx.

WikiDocs at root of a domain

This is my configuration that hosts WikiDocs at /var/www/wiki.local/public_html/ with wiki.local domain.

server {
    listen               80;
    server_name          wiki.local;
    add_header           Strict-Transport-Security "max-age=31536000" always;
    add_header           X-Frame-Options "SAMEORIGIN";
    add_header           X-XSS-Protection "1; mode=block";
    add_header           X-Content-Type-Options "nosniff";
    # no cache
    add_header           Last-Modified $date_gmt;
    add_header           Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    if_modified_since    off;
    expires              off;
    etag                 off;
    root                 /var/www/wiki.local/public_html/;
    index                index.html index.htm index.php;
    # access_log         /var/log/nginx/wiki.local_access.log;
    # error_log          /var/log/nginx/wiki.local_error.log;
    location / {
        if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php?doc=$1 last;
        }
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        # try_files        $uri =404;
        fastcgi_pass     unix:/run/php/php8.1-fpm.sock;
        include          /etc/nginx/snippets/fastcgi-php.conf;
        include          /etc/nginx/fastcgi_params;
        fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param    SCRIPT_NAME        $fastcgi_script_name;
    }
    location ~ /\.ht {
        deny all;
    }
}

WikiDocs at wikidocs subfolder of a domain

Use this configuration if you want to host it at wikidocs subfolder that hosts WikiDocs at /var/www/wiki.local/public_html/wikidocs/ with wiki.local/wikidocs/ domain.

server {
    listen               80;
    server_name          wiki.local;
    add_header           Strict-Transport-Security "max-age=31536000" always;
    add_header           X-Frame-Options "SAMEORIGIN";
    add_header           X-XSS-Protection "1; mode=block";
    add_header           X-Content-Type-Options "nosniff";
    # no cache
    add_header           Last-Modified $date_gmt;
    add_header           Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    if_modified_since    off;
    expires              off;
    etag                 off;
    root                 /var/www/wiki.local/public_html/;
    index                index.html index.htm index.php;
    # access_log         /var/log/nginx/wiki.local_access.log;
    # error_log          /var/log/nginx/wiki.local_error.log;
    location /wikidocs/ {
        if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php?doc=$1 last;
        }
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        # try_files        $uri =404;
        fastcgi_pass     unix:/run/php/php8.1-fpm.sock;
        include          /etc/nginx/snippets/fastcgi-php.conf;
        include          /etc/nginx/fastcgi_params;
        fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param    SCRIPT_NAME        $fastcgi_script_name;
    }
    location ~ /\.ht {
        deny all;
    }
}

leomoon avatar May 21 '23 22:05 leomoon

@brentonv were you able to make it work?

Zavy86 avatar May 31 '23 13:05 Zavy86

I think I'll be testing this config before long. I'll let you know if it works.

EzequielBruni avatar Jun 06 '23 00:06 EzequielBruni

@EzequielBruni any news?

Zavy86 avatar Oct 13 '23 07:10 Zavy86

Oh, crap, right. This was a while ago, and I hardly remember. Given that I went with Bookstack, I suspect it did not work.

EzequielBruni avatar Oct 13 '23 09:10 EzequielBruni