使用两个php-fpm fastcgi_pass位置配置nginx

时间:2016-11-15 19:11:58

标签: php nginx fastcgi nginx-location

对于使用nginx + php-fpm的wordpress网站我有兴趣将更长的 fastcgi_read_timeout 指令应用于 / wp-admin 目录,以避免超时管理员的超时任务。

以下代码示例的唯一问题是,当我访问http://webpage.org/wp-admin时,我获得了404.当我访问http://webpage.org/wp-admin/index.php页面帖子时。

使用nginx add-header 指令来帮助我调试我已经能够确定在访问http://webpage.org/wp-admin时nginx选择了 location~.php $ 位置^〜/ wp-admin

有关如何解决此问题的任何想法?感谢

location ^/wp-admin/.*.(php|phps)$  {

    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    fastcgi_keep_conn on;

    fastcgi_read_timeout 120;
}



location ~ \.php$ {

    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    fastcgi_keep_conn on;

   }

1 个答案:

答案 0 :(得分:1)

  • 我测试了对Keenan Lawrence建议的 try_files 指令的更改,该指令为我解决了问题。

  • 有关nginx try_files 指令的有用说明,请访问:how can i make this try_files directive work?

  • 要解决此问题,我使用 add_header 指令,在每个位置放置一个指令。然后使用Chrome浏览器打开开发者工具,点击网络标签,点击记录网络日志,然后加载测试wp-admin / page 。然后,您可以点击标题标签来验证网页的加载位置。另请参阅https://serverfault.com/questions/404626/how-to-output-variable-in-nginx-log-for-debugging

  • 下面的工作配置包括用于调试的头指令。

     location ~* ^/wp-admin/.*.(php|phps)$  {
    
        add_header X-debug-message "This page processed from location ^~ /wp-admin . uri =  $uri ." always;
    
        try_files $uri $uri/ =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        fastcgi_keep_conn on;
    
        fastcgi_read_timeout 120;
    }
    
    
    
    location ~ \.php$ {
    
    add_header X-debug-message "This page processed from location ~ \.php uri =  $uri ." always;
    
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        fastcgi_keep_conn on;
    
       }