首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有php-fpm url编码的Nginx

具有php-fpm url编码的Nginx
EN

Server Fault用户
提问于 2018-01-28 12:09:27
回答 1查看 1K关注 0票数 0

我也在堆栈过流上发布了我的问题,但我认为这里更适合提问。

我使用了docker,并为数据库目的设置了一个nginx容器和nginx 1.12.2,一个php容器,5.6.33和一个mariadb容器。我已经设法服务器一个drupal网站,一切看起来都很好,除了urls。

当我点击一个链接时,我得到的是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.ini参数配置错误(比如www.conf或php.ini)

我的nginx配置如下:

代码语言:javascript
复制
# 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;
    }
}
EN

回答 1

Server Fault用户

发布于 2018-01-28 15:47:35

感谢迈克尔·汉普顿,我改变了我的观点,开始寻找与drupal相关的问题。我读到覆盖模块不能很好地处理干净urls。我确信我已经完成了url工作所需的每一项工作,所以我甚至不认为这是Drupal的一个干净的url问题。正如我在这里所读到的,配置清洁Urls的Drupal官方文档关于虚假否定:

清洁- Urls测试-一些设置上的假阴性,清洁Urls测试给出一个假阴性的结果。如果您可以访问http://example.com/user/login和Drupal之类的清洁Url链接,则.htaccess和mod_rewrite将返回用户登录页面。直接访问http://example.com/admin/config/search/clean-urls的Clean管理页面,应该会给您一个复选框,使您能够启用清洁URL(注意在URL中缺少"?q=“)。见http://drupal.org/node/1178850注意:如果像http://example.com/user/login这样的干净Urls。停止工作(切换主机),您可以通过将URL更改为:http://www.example.com/?q=user/login访问相同的页面。

所以解决办法非常简单。我访问了http://localhost/admin/config/search/clean-urls,并检查了一下以启用干净的urls。就是这样。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/894479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档