Nginx с кодировкой URL-адресов php-fpm

Я также разместил свой вопрос в Stackoverflow , но я думаю, что это более подходящее место, чтобы спросить.

Я использую докер и установил контейнер nginx с nginx 1.12.2, контейнер php-fpm с версией 5.6.33 и контейнер mariadb для целей базы данных. Мне удалось создать сервер на drupal-сайте, и все выглядит нормально, кроме URL-адресов.

Когда я нажимаю ссылку, я получаю http: // localhost / # overlay =% 3Fq% 3Dadmin% 252Fconfig вместо http: // localhost / # overlay = admin / config .

Я не могу понять, почему это происходит. Страница работает правильно, и в журнале nginx я получаю:

[28 / Янв / 2018: 11: 55: 14 +0000] "GET /? Q = admin% 2Fconfig & render = overlay HTTP / 1.1" 200 11405 "-" "Mozilla / 5.0

Я не Не знаю, проблема ли это nginx или что-то неправильно сконфигурировано в параметрах php-fpm (например, www.conf или php.ini)

Моя конфигурация nginx следующая:

# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
  default $http_x_forwarded_proto;
  ''      $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
  default $http_x_forwarded_port;
  ''      $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
  default upgrade;
  '' close;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
# Set appropriate X-Forwarded-Ssl header
map $scheme $proxy_x_forwarded_ssl {
  default off;
  https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"';
access_log off;
resolver 127.0.0.11;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    listen 80;
    access_log /var/log/nginx/access.log vhost;
    return 503;
}
# localhosy
upstream localhost {
                ## Can be connect with "ngproxy" network
            # localhost
            server 172.18.0.3:9000;
}
server {
    server_name localhost;
    listen 80 ;
    root   /var/www/html;
    index index.php index.html index.htm;
    access_log /var/log/nginx/access.log vhost;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # Very rarely should these ever be accessed outside of your lan
    location ~* \.(txt|log)$ {
        allow 192.168.0.0/16;
        deny all;
    }

    location ~ \..*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
        return 403;
    }

    # Allow "Well-Known URIs" as per RFC 5785
    location ~* ^/.well-known/ {
        allow all;
    }

    # Block access to "hidden" files and directories whose names begin with a
    # period. This includes directories used by version control systems such
    # as Subversion or Git to store control files.
    location ~ (^|/)\. {
        return 403;
    }

    location / {
        # try_files $uri @rewrite; # For Drupal <= 6
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }


    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

    # In Drupal 8, we must also match new paths where the '.php' appears in
    # the middle, such as update.php/selection. The rule we use is strict,
    # and only allows this pattern with the update.php front controller.
    # This allows legacy path aliases in the form of
    # blog/index.php/legacy-path to continue to route to Drupal nodes. If
    # you do not have any paths like that, then you might prefer to use a
    # laxer rule, such as:
    #   location ~ \.php(/|$) {
    # The laxer rule will continue to work if Drupal uses this new URL
    # pattern with front controllers other than update.php in a future
    # release.
    location ~ '\.php$|^/update.php' {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        # Security note: If you're running a version of PHP older than the
        # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
        # See http://serverfault.com/q/627903/94922 for details.
        include fastcgi_params;
        # Block httpoxy attacks. See https://httpoxy.org/.
        fastcgi_param HTTP_ACCEPT_ENCODING "";
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_intercept_errors on;
        # PHP 5 socket location.
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        # PHP 7 socket location.
        fastcgi_pass drupal:9000;
    }

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    # Handle private files through Drupal. Private file's path can come
    # with a language prefix.
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }
}
0
задан 28 January 2018 в 14:09
1 ответ

Благодаря Майклу Хэмптону я изменил свою точку зрения и начал искать проблему, связанную с drupal. Я читал, что модуль оверлея не может работать с не чистыми URL-адресами. Я был почти уверен, что проделал всю работу, необходимую для работы URL-адресов, поэтому я даже не подумал, что это проблема с чистым URL-адресом Drupal. Как я читал здесь, Официальная документация Drupal о настройке чистых URL-адресов о ложно-отрицательных:

Тест чистых URL-адресов - ложно-отрицательные

На некоторых настройках тест чистых URL-адресов дает ложноотрицательный результат. Если вы можете перейти по ссылкам Clean Url, например http://example.com/user/login , а Drupal возвращает страницу входа пользователя, то .htaccess и mod_rewrite работают. Посещение административной страницы очистки URL-адресов непосредственно по адресу http://example.com/admin/config/search/clean-urls должно дать вам флажок, позволяющий включить очистку URL-адресов (обратите внимание на отсутствие "?" q = "в URL-адресе). См. http://drupal.org/node/1178850 . Примечание: Если чистые URL-адреса вида http://example.com/user/login . перестает работать (переключение хостов), вы можете посетить ту же страницу, изменив URL-адрес, чтобы он выглядел так: http://www.example.com/?q=user/login .

Итак, решение было чрезвычайно просто. Я захожу на сайт http: // localhost / admin / config / search / clean-urls и просто проверяю, разрешены ли чистые URL-адреса. Вот и все.

0
ответ дан 24 November 2019 в 03:12

Теги

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