NGINX виртуальный подкаталог служит файлам PHP в качестве загрузок

Мой сервер отвечает на следующие виртуальные пути подкаталога:

www.domain.com/us www.domain.com/ca www.domain.com/fr-ca www.domain.com/spa

Каждый из них является псевдонимом для www.domain.com.

Если я пытаюсь получить доступ к www.domain.com/some/virtual/path, это правильно передано к моему index.php и обработано PHP-FPM.

Если я пытаюсь получить доступ к www.domain.com/us/some/virtual/path, это правильно передано к моему index.php и обработано PHP-FPM

Однако, если я пытаюсь назвать www.domain.com/us/file.php, NGINX пытается служить файлу в качестве загрузки. Но без виртуального тракта, это обрабатывается соответственно PHP-FOM.

Мои виртуальные пути подкаталога настроены этим разделом в моей конфигурации NGINX:

    ####
    # Catch virtual locations: /us, /ca, /fr-ca, /spa
    ####
    location ~ ^\/(?:(?<currentSite>us|ca|fr-ca|spa)(?:\/|$))(?<realPath>.*) {
        try_files /$realPath /$realPath/;
        break;
    }

.

server {
    listen       443 ssl;
    listen       80;
    listen   [::]:80 default ipv6only=on;
    server_name  localhost;

    ssl_certificate      /certs/cert.pem;
    ssl_certificate_key  /certs/cert.key;

    root   ${LANDO_WEBROOT};
    index index.php index.html index.htm;

    ######
    # CloudFlare limit for headers is 8K - development should simulate this

    large_client_header_buffers 4 8k;

    ####
    # Catch virtual locations: /us, /ca, /fr-ca, /spa
    ####
    location ~ ^\/(?:(?<currentSite>us|ca|fr-ca|spa)(?:\/|$))(?<realPath>.*) {
        try_files /$realPath /$realPath/;
        break;
    }

    ####
    # Manage the REAL locations
    ####
    location /js {
        index index.html
        expires 100d;
        add_header Pragma public;
        add_header Cache-Control "public";
        try_files $uri $uri/ =404;
        break;
    }

    location /media {
        index index.html
        expires 100d;
        add_header Pragma public;
        add_header Cache-Control "public";
        try_files $uri $uri/ =404;
        break;
    }

    location /skin {
        index index.html
        expires 100d;
        add_header Pragma public;
        add_header Cache-Control "public";
        try_files $uri $uri/ =404;
        break;
    }

    location @handler {
        rewrite / /index.php;
    }

    location / {
        try_files $uri $uri/ @handler;
    }

    location ~ \.php$ {
        # Try to load the file if requested, if not found, rewrite to @missing
        # This should pass all requests through index.php

        try_files $uri =404;

        fastcgi_param MAGE_IS_DEVELOPER_MODE true;
        fastcgi_buffers 256 500k; #Allow a greater amount of data to be included in cookies
        fastcgi_buffer_size 1000k;  #Allow a greater amount of data to be included in cookies

        fastcgi_pass fpm:9000;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_connect_timeout 300s;
        fastcgi_send_timeout 300s;
        fastcgi_read_timeout 300s;
        include fastcgi_params;
    }
}
1
задан 10 July 2018 в 00:44

1 ответ

Можно использовать a rewrite...last удалить префикс языка из URI, так, чтобы это могло быть обработано правильно остающимися местоположениями в Вашей конфигурации. В частности, .php URIs должен быть обработан location ~ \.php$ блок.

Например:

location ~ ^/(?:(?<currentSite>us|ca|fr-ca|spa)(?:/|$))(?<realPath>.*) {
    rewrite ^ /$realPath last;
}

Или проще:

rewrite ^/(us|ca|fr-ca|spa)(?:/(.*))? /$1 last;

См. этот документ для деталей.

1
ответ дан 7 December 2019 в 15:16

Другие вопросы по тегам:

Похожие вопросы: