Nginx Location Configuration (Subfolders)

says i have a way:

/var/www/myside/

this path contains two folders ... let them say /staticand/manage

I want to configure nginx to access:

/staticon /(e.g. http://example.org/ ) this folder has some .html files.

/manageon /manage(for example, http://example.org/manage ), in this case this folder contains Slim PHP framework code - this means that the index.php file is in a subfolder public(for example, / var / www / mysite / manage / public /index.php)

I tried many combinations like

server {
listen 80;
server_name  example.org;
error_log /usr/local/etc/nginx/logs/mysite/error.log;
access_log /usr/local/etc/nginx/logs/mysite/access.log;
root /var/www/mysite;

location /manage {
  root $uri/manage/public;

  try_files $uri /index.php$is_args$args;
}

location / {
  root $uri/static/;

  index index.html;
}

location ~ \.php {
  try_files $uri =404;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  fastcgi_index index.php;
  fastcgi_pass 127.0.0.1:9000;
}

}

/It works correctly, in any case it managedoes not work. Am I doing something wrong? Does anyone know what I have to change?

Matthew.

+4
1

, /var/www/mysite/manage/public URI, /manage, alias, root. . .

, PHP , location ~ \.php, . . PHP /var/www/mysite/static, location.

:

server {
    listen 80;
    server_name  example.org;
    error_log /usr/local/etc/nginx/logs/mysite/error.log;
    access_log /usr/local/etc/nginx/logs/mysite/access.log;

    root /var/www/mysite/static;
    index index.html;

    location / {
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    }

    location ^~ /manage {
        alias /var/www/mysite/manage/public;
        index index.php;

        if (!-e $request_filename) { rewrite ^ /manage/index.php last; }

        location ~ \.php$ {
            if (!-f $request_filename) { return 404; }
            fastcgi_pass 127.0.0.1:9000;

            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        }
    }
}

^~ . . .

alias try_files - .

if.

+2

Source: https://habr.com/ru/post/1670766/


All Articles