我也在堆栈溢出但我认为这里是更适合提问的地方。
我使用 docker,并设置了一个 nginx 1.12.2 的 nginx 容器、一个 php-fpm 容器和一个用于数据库的 mariadb 容器。我已经成功为 drupal 网站提供服务,除了 URL 之外,一切看起来都很好。
当我点击一个链接时,我得到的http://localhost/#overlay=%3Fq%3Dadmin%252Fconfig
是http://localhost/#overlay=admin/config
。
我不明白为什么会发生这种情况。该页面运行正常,在 nginx 日志中我得到:
[28/Jan/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;
}
}
答案1
感谢 Michael Hampton,我改变了我的观点,开始寻找与 drupal 相关的问题。我读到覆盖模块无法很好地与非清理 URL。我很确定我已经完成了 URL 正常工作所需的所有工作,所以我甚至不认为这是 Drupal 的清理 URL 问题。正如我在这里读到的,Drupal 官方文档关于配置干净的 URL关于假阴性:
Clean-Urls 测试 - 误判
在某些设置下,Clean Urls 测试会给出假阴性结果。如果您可以访问 Clean Url 链接,例如,
http://example.com/user/login
并且 Drupal 返回用户登录页面,则 .htaccess 和 mod_rewrite 正在运行。直接访问 Clean Urls 管理页面http://example.com/admin/config/search/clean-urls
,应该会显示一个复选框,让您启用 Clean Urls(请注意 URL 中没有“?q=”)。请参阅http://drupal.org/node/1178850。笔记:如果 Clean Urls likehttp://example.com/user/login
. 停止工作(切换主机),您可以通过将 URL 更改为如下所示来访问同一页面:http://www.example.com/?q=user/login
。
所以解决方案非常简单。我访问http://localhost/admin/config/search/clean-urls
并检查是否启用了干净的 URL。就这样。