0

One down, one to go! I fully understand everything that was wrong with my config before and would like to thank Cemal over at Stack Overflow once again. The /location/ is now displaying index.php.

The new problem is, the rewrite rules. They are currently set globally and each location needs to do the same thing (they are duplicated PHP front ends but one has limited access to certain things.)

At the moment the main domain.com works, but the mydomain.com/test is loading the main PHP but not passing the data from the rewrites . I've found a way to make it work with try files, but am struggling to get it working using the advice of regex found here.

As it stands without try, the following leads to errors of not being able to find raw_data or general_data in nginx despite these files existing so I can only assume it has to be the rewrite rules.

I cloned the existing rewrite rules and prefixed them with the /test2/ but it's still unable to locate them.

2018/02/27 13:37:46 [error] 31485#31485: *49483 open()

"/var/www/html/test2/general_data" failed (2: No such file or
directory), client: X.X.X.X, server: mydomain.co.uk, request: "POST
/test/weather_data?cell HTTP/1.1", host: "mydomain.co.uk", referrer:
"https://mydomain.co.uk/test2/" 2018/02/27 13:37:46 [error]
31485#31485: *49546 open() "/var/www/html/test/raw_data" failed (2: No
such file or directory), client: X.X.X.X, server: my domain.co.uk,
request: "POST /test/raw_data HTTP/1.1", host: "mydomain.co.uk",
referrer: "https://mydomain.co.uk/test2/"

that is the error that's lead me to the conclusion anyway.

Here is my current config the relevant parts -

}server {

    rewrite ^/raw_data$ /raw_data.php?$1 last;
    rewrite ^/test_data$ /test_data.php?$1 last;
    rewrite ^/motd_data$ /motd_data.php?$1 last;
    rewrite ^/(.*)map.common.js$ /static/js/map.common.php last;
    rewrite ^/general_data$ /general_data.php?$1 last;

    rewrite ^test2/raw_data$ /test2/raw_data.php?$1 last;
    rewrite ^test2/test_data$ /test2/test_data.php?$1 last;
    rewrite ^test2/motd_data$ /test2/motd_data.php?$1 last;
    rewrite ^test2/(.*)map.common.js$ /PMSFE/static/js/map.common.php last;
    rewrite ^test2/general_data$ /PMSFE/general_data.php?$1 last;



    location / {
    include /etc/nginx/mime.types;
        index index.php index.html index.htm;
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
            fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
      }
    }

    location /test2 {
    include /etc/nginx/mime.types;
    root /var/www/html/;
        index index.php index.html index.htm;
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
            fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
      }
    }

Any advice on how I can get this working would be really appreciated, this is my first time using Linux in general, let alone trying to host something substantial, unfortunately the nginx examples you find around are so different it's hard to gauge what applies to your particular situation or not.

I tried to include the rewrite rules in each location as I'd seen on another post, but this broke the mydomain.co.uk page with the same error as the new mydomain.co.uk/test2/

PBX
  • 11
  • 4

1 Answers1

0

So Silly of me. One / short on my rewrites.

rewrite ^/test2/raw_data$ /test2/raw_data.php?$1 last;
rewrite ^/test2/test_data$ /test2/test_data.php?$1 last;
rewrite ^/test2/motd_data$ /test2/motd_data.php?$1 last;
rewrite ^/test2/(.*)map.common.js$ /PMSFE/static/js/map.common.php last;
rewrite ^/test2/general_data$ /PMSFE/general_data.php?$1 last;

now works!

PBX
  • 11
  • 4