#php #wordpress #nginx #get #fastcgi
Вопрос:
У меня есть WordPress, работающий на Nginx (с использованием FastCGI, PHP-FPM), 4 виртуальных хоста (4 сайта), которые работают на одной машине. Все работает как по маслу, но когда дело доходит до выполнения параметра GET, происходит что-то странное, например, я запускаю: example.com/wp-content/themes/kdi-ecommerce/templates/mobile-player.php?source=https://d343552mf.cloudfront.net/content/d32324m93k.m3u8
Я пробовал различные решения, показанные здесь (StackOverflow) и в некоторых других местах, но ни одно из них не работает, я пробовал изменять файл wordpress.conf, добавляя/удаляя/редактируя разными способами и в разных местах, например: я пробовал в основном все варианты параметра «try_files», вот несколько из них, которые я пробовал, и тот, который в настоящее время настроен на «работу» в моем коде:
location / {
#try_files $uri $uri/ /index.php?$args;
#try_files $uri $uri/ /index.php?q=$uriamp;$args;
try_files $uri $uri/ /index.php?$query_string;
}
Я также попытался изменить размер буфера в конфигурации кэша # Fast-CGI, как показано в приведенном ниже коде, хотя это на самом деле улучшило скорость загрузки моих сайтов, это не помогло решить проблему с параметром GET, которая не работает.
Я даже добавил строку кода на mobile-player.php в моем браузере, который должен был напечатать параметр GET, но все, что он возвращает, равно НУЛЮ, это похоже на то, что параметр GET не отправляется на мой сервер, даже если вы можете увидеть его по URL (пример URL, показанный выше).
Мой файл wordpress.conf выглядит следующим образом:
# Restrictions
# Disable logging for favicon and robots.txt
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;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
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;
#try_files $uri $uri/ /index.php?q=$uriamp;$args;
try_files $uri $uri/ /index.php?$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$ {
include fastcgi-cache.conf;
include fastcgi.conf;
fastcgi_intercept_errors on;
#fastcgi_pass unix:run/php-fpm/www.sock;
fastcgi_pass 127.0.0.1:9000;
# 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;
#proxy_read_timeout 300;
#proxy_connect_timeout 6000;
#proxy_send_timeout 6000;
#send_timeout 60;
}
Also, on the fastcgi.conf file there’s a line of code that should pass POST and GET parameters to be handled and it’s not working for me:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Проблема не только влияет на мои параметры GET, но и на параметры POST, для справки, у меня есть точно такой же сайт, работающий на apache, и все это отлично работает там, поэтому я решил, что это как-то связано с плохой конфигурацией между файлами связи Nginx и FastCGI.
Все ответы были бы очень признательны.