php - NGINX - WORDPRESS - PHP-FPM:查询参数(GET)未传入子文件夹
问题描述
我有一个使用 NGINX(和 Php-fpm)和 4 个虚拟主机运行的 wordpress 站点,一切正常,除非我想传递一个查询字符串。看,如果我这样做,它会起作用:
example.com/phpfile.php?var=123
但如果我尝试,它不会
exaple.com/subfolder/subfolder2/phpfile.php?var=123
这是我的 /nginx/snippets/wordpress.conf:
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
try_files $uri /index.php?$args;
}
location ~ /\. {
deny all;
}
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# End Restrictions
# Caching
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $no_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
#end Caching
# WordPress single site rules.
location / {
try_files $uri $uri/ /index.php?$args;
}
#location /wp-content/themes/kdi-ecommerce/templates/ {
# try_files $uri $uri/ /index.php$is_args$query_string;
#}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(eot|otf|woff|woff2|ttf|rss|atom|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
# Media: images, icons, video, audio send expires headers.
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript send expires headers.
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# HTML send expires headers.
location ~* \.(html)$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
}
# Browser caching of static assets.
location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
expires 7d;
add_header Cache-Control "public, no-transform";
}
# Enable Gzip compression in NGNIX.
gzip on;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
# Fast-CGI Cache configuration
location ~ \.php$ {
#location ~ [^/]\.php(/|$){
#fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#if (!-f $document_root$fastcgi_script_name) {
# return 404;
#}
include fastcgi-cache.conf;
include fastcgi.conf;
#fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:run/php-fpm/www.sock;
#enable cache
add_header X-WP-Cache $upstream_cache_status;
# Skip cache based on rules in snippets/fastcgi-cache.conf.
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
# Define memory zone for caching. Should match key_zone in fastcgi_cache_path above.
fastcgi_cache restorebindemo;
# Define caching time.
fastcgi_cache_valid 60m;
#PHP-FTP Buffers
fastcgi_buffers 8 4k;
fastcgi_buffer_size 8k;
#increase timeouts
fastcgi_read_timeout 60s;
fastcgi_connect_timeout 60s;
fastcgi_send_timeout 60s;
}
我尝试过所有类型的 try_files 变体;我不知道它是否是位置/块配置。
这是 fastcgi.conf:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
如前所述,如果我将需要使用参数执行的 php 文件放在 / (与 wp-config.php 文件相同的位置)中,它可以工作,但在子目录中没有。
解决方案
推荐阅读
- javascript - 抓取对象而不在数组中重复的最有效方法
- angular - 排序列上的 Angular 8 ng-bootstrap 表头键盘导航
- excel - 运行参考文件的自动打开
- audio - arecord:main:828:音频打开错误:设备或资源繁忙 RPi 4
- java - 我有一个类需要访问其他 3 个数据类
- jestjs - 开玩笑如何在 CLI 中查看所有未发现的行?
- python - 由于 jsonschema 无法打开 jupyter notebook [已经在 stackoverflow 上尝试过其他解决方案]
- tensorflow - pytorch 与 tensorflow 2.0 的视图等效性是什么?
- c# - 添加列表项并获取 NullReferenceException C#
- powershell - Powershell RDS CAL 电子邮件报告