Skip to content

Changes to recommended nginx config #60

Description

@ChillyCider

I was able to get nginx up and running with a mix of reading https://picocms.org/in-depth/nginx/ and the helpful discussions at picocms/Pico#343 and picocms/Pico#350.

So yeah, it sort of worked. There was a weird problem, though. I opened my browser to /vendor/ to make sure the 404 worked, and it downloaded a plain-text version of index.php to my hard drive.

I was confuse. 😂

But, I managed to fix it! After some struggle, here's my new config. Would it be ok if I submit a PR to get this onto the "How to Configure Nginx for Pico" page?

Here's the fixed nginx config:

    ...

    # 404 on the theme's README, CHANGELOG, etc.
    location ~ ^/themes(/?$|/[^/]+(/?$|/[^/]+/?$)) {
        error_page 404 /index.php;
        return 404;
    }

    # 404 on PicoCMS README, CHANGELOG, and other forbiddens
    location ~ ^/((CHANGELOG.md|CONTRIBUTING.md|LICENSE|README.md|plugins|config|content|vendor|composer\.(json|lock|phar))(/|$)|(.+/)?\.(?!well-known(/|$))) {
        error_page 404 /index.php;
        return 404;
    }

    # Rewrite all other requests to go to the front controller
    location / {
        error_page 404 /index.php;
        try_files $uri $uri/ /index.php$uri =404;
    }

    # Front controller
    location ~ ^/index\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        try_files $fastcgi_script_name =404;

        fastcgi_param HTTP_PROXY "";
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;

        include fastcgi_params;
    }

    ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions