0

According to the config, site.com should open html/web/index.php by default, however site.com/ticket should open html/ticket/index.php. Both ticket and web folders located in html.

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;

    server_name  site.com;
    server_tokens off;

    root /usr/share/nginx/html/web;

    location / {
        index index.php;
    }

    error_page   404              /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include         fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny  all;
    }

    location /ticket {
            root /usr/share/nginx/html/ticket;
            index index.php index.html index.htm;
    }
}

It opens web/index.php, however for /ticket it says Not found.

UPDATE

The above looks in /usr/share/nginx/html/ticket/ticket/index.php

I tried also

location /ticket {
    root /usr/share/nginx/html;
    index index.php index.html index.htm;
}

and

location /ticket {
    alias /usr/share/nginx/html/ticket;
    index index.php index.html index.htm;
}

Both configs look in /usr/share/nginx/html/web/ticket/index.php.

It should look in /usr/share/nginx/html/ticket/index.php

I suppose, problem is in FastCGI

SOLUTION

The problem was in FastCGI configurations

        try_files  $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
  • This isn't the full config is it? You have a "return" to https and `Strict-Transport-Security` so this site should be using https, yet there are no SSL configuration settings. So perhaps something in the rest of the config is causing the solutions below to not work – Drifter104 Aug 04 '17 at 16:34
  • @Drifter104 yes, there are SSL configs, where I include certificates. How could it affect? – Tarlan Mammadzada Aug 04 '17 at 18:08
  • Please add your solution as an answer to the question. – Tero Kilkanen Aug 05 '17 at 11:21

3 Answers3

1

You need to use the alias directive. nginx does not add the full normalized URI after directory specified with alias, like it does with root.

So, your block would look like:

location /ticket {
    alias /usr/share/nginx/html/ticket;
    index index.php index.html index.html;
}
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
0

See the documentation for the root directive. Inside location, it's still root relative rather than relative to that particular location.

Sets the root directory for requests. For example, with the following configuration

location /i/ {
    root /data/w3;
}

The /data/w3/i/top.gif file will be sent in response to the /i/top.gif request.

Therefore, you should have:

location /ticket/ {
    root /usr/share/nginx/html;
    index index.php index.html index.htm;
}

Otherwise it's trying to access /usr/share/nginx/html/ticket/ticket/index.php, instead.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
0

This will work. I have tested it.

server {

    server_name  site.com;
     server_tokens off;
    root /usr/share/nginx/html/web; 

   location / {
        index index.php;
    }

   location /ticket  {
        index index.php;
        alias /usr/share/nginx/html/ticket/;


    if (-f $request_filename) {
        break;
    }


    if (-d $request_filename) {
        break;
    }

    rewrite (.*) /ticket/index.php?$query_string;        

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

        }



    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }


}
Mukesh Jagani
  • 237
  • 1
  • 3