Страница 1 из 1
Переделка htaccess в nginx
Добавлено: 2015-06-25 17:57:22
eFusion
Всем привет!
Имеется вордпрессовский htaccess:
Код: Выделить всё
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
И вот конфиг nginx:
Код: Выделить всё
server {
listen 80;
server_name my_site;
access_log /var/log/nginx/www.my_site_log;
error_log /var/log/nginx/www.my_site-error_log;
set $root_path '/usr/local/www/data/my_site';
location / {
try_files $uri $uri /index.php;
root $root_path;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
location ~ \.php$ {
fastcgi_pass 1.1.1.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/data/my_site$fastcgi_script_name;
#fastcgi_param QUERY_STRING $query_string;
include fastcgi_params;
}
# Static files location
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
root /usr/local/www/data/my_site;
}
location ~ /\.ht {
deny all;
}
}
С такой вариацией открывается главная, а при попытке перейти по ссылке куда-нибудь - 404 Not found.
В адресной строке, при этом, приходит параметр ссылки, т.е. видим там такое
my_site/about.php
Подобный конфиг еще на нескольких сайтах отрабатывает нормально.
Я так понимаю, что проблема в локации location ~ \.php$.
Если пробовать как советуют в кодексе вордпресса:
Код: Выделить всё
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
}
- не открывается даже главная.
Подсобите кто чем может.
Спасибо!
Переделка htaccess в nginx
Добавлено: 2015-06-26 9:03:06
bagas
Код: Выделить всё
# nginx configuration
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}
Перевод htaccess в nginx, так думаю пойдет.
Переделка htaccess в nginx
Добавлено: 2015-06-26 10:09:58
eFusion
Если в имеющимся конфиге заменить существующую локацию / на кусок выше - даже на главной 404 not found.
Может в nginx-е как и в апаче нужно подключить мод_реврайт? Потому что такое чувство, что он не умеет рерайтить...
Переделка htaccess в nginx
Добавлено: 2015-06-26 10:19:20
bagas
eFusion писал(а):Если в имеющимся конфиге заменить существующую локацию / на кусок выше - даже на главной 404 not found.
Может в nginx-е как и в апаче нужно подключить мод_реврайт? Потому что такое чувство, что он не умеет рерайтить...
nginx -V смотри подключен ли модуль.
Переделка htaccess в nginx
Добавлено: 2015-06-26 18:20:43
PYO
Переделка htaccess в nginx
Добавлено: 2015-07-02 10:41:43
eFusion
Разобрался. Вот мой конфиг для wordpress:
Код: Выделить всё
server {
listen 80;
server_name mysite.com;
access_log /var/log/nginx/www.mysite.com_log;
error_log /var/log/nginx/www.mysite.com-error_log;
set $root_path '/usr/local/www/data/mysite.com';
location / {
try_files $uri @wordpress;
}
location @wordpress {
fastcgi_pass X.X.X.X:9000;
fastcgi_param SCRIPT_FILENAME $root_path/index.php;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
# Static files location
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
root /usr/local/www/data/mysite.com;
}
location ~ /\.ht {
deny all;
}
}
Переделка htaccess в nginx
Добавлено: 2015-07-03 10:38:48
eFusion
Возникла другая проблема - при попытке зайти в админку, получаю циклическую переадресацию.
Конфиг, такаой как в примере выше.
Роботс не блочит ничего (все закоментил).
На апаче тот же набор файлов работает нормально.
Права на файлы wp-login.php и /wp-admin/index.php 644
Что можно предпринять?
Переделка htaccess в nginx
Добавлено: 2015-07-03 17:00:42
bagas
Попробуй с таким конфигом.
Есть же специально уже созданные офф. примеры.
https://codex.wordpress.org/Nginx
Код: Выделить всё
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~ /\. {
deny all;
}
Переделка htaccess в nginx
Добавлено: 2015-07-03 17:46:33
eFusion
Пробовал уже:
404 Not Found
nginx/1.8.0
Переделка htaccess в nginx
Добавлено: 2015-07-03 21:37:47
Alex Keda
а чем индеец не устраивает-то?
Переделка htaccess в nginx
Добавлено: 2015-07-04 9:01:19
bagas
Alex Keda писал(а):а чем индеец не устраивает-то?
Тяжеловат по весу индеец, я от него отказываюсь в пользу nginx.
Переделка htaccess в nginx
Добавлено: 2015-07-04 17:21:03
Alex Keda
Чё-то тяжеловат?
Рама - нынче копейки стоит, процы - многовёдерные...
В любом случае, узким местом php станет....
Переделка htaccess в nginx
Добавлено: 2015-07-07 10:45:49
eFusion
И все-таки, будут какие-то мысли?
Переход обратно на апач - не вариант т.к. он течет по памяти и виснет весь сервак.
"Иди читай на офф.форум или сайт" - не вариант т.к. перечитаны тонны информации.
Может внесет какую-то ясность, ошибка из лога нжинкса, когда получаю в браузере 500 Internal Server Error:
Код: Выделить всё
2015/07/07 07:23:45 [error] 12592#0: *170 rewrite or internal redirection cycle while internally redirecting to "/wp-admin/index.php", client: 192.168.2.113
, server: mysite.com, request: "GET /wp-admin/index.php HTTP/1.1", host: "mysite.com"
Ошибка вылезла, когда в конфиг добавил такую локацию:
Код: Выделить всё
location /wp-admin {
try_files $uri $uri/ /wp-admin/index.php?$args;
}
Спасибо!
Переделка htaccess в nginx
Добавлено: 2015-07-07 10:53:19
bagas
покажи конфиг nginx.con и конфиг виртуал хста сайта.
Я не поверю, что офф. материал не подходит!
Переделка htaccess в nginx
Добавлено: 2015-07-07 11:07:00
eFusion
Код: Выделить всё
user www;
worker_processes 4;
error_log /var/log/nginx/nginx_error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
use kqueue;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/nginx_access.log;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name mysite.com;
access_log /var/log/nginx/www.mysite.com_log;
error_log /var/log/nginx/www.mysite.com-error_log;
set $root_path '/usr/local/www/data/mysite.com';
location / {
try_files $uri @wordpress;
}
location @wordpress {
fastcgi_pass x.x.x.x:9000;
fastcgi_param SCRIPT_FILENAME $root_path/index.php;
include fastcgi_params;
}
location /wp-admin {
try_files $uri $uri/ /wp-admin/index.php?$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
root /usr/local/www/data/mysite.com;
}
location ~ /\.ht {
deny all;
}
}
}
Переделка htaccess в nginx
Добавлено: 2015-07-07 11:42:10
bagas
Для чего вывел обработку wp-admin в отдельный локейшен?
Код: Выделить всё
location /wp-admin {
try_files $uri $uri/ /wp-admin/index.php?$args;
}
Переделка htaccess в nginx
Добавлено: 2015-07-07 11:53:28
eFusion
Ради теста.
Думал, может так перекинет меня на wp-admin
Переделка htaccess в nginx
Добавлено: 2015-07-07 12:02:31
bagas
Давайка ты офф. пример сделай.
Код: Выделить всё
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~ /\. {
deny all;
}
И покажи логи нгинса.
Переделка htaccess в nginx
Добавлено: 2015-07-07 15:25:45
eFusion
Код: Выделить всё
[crit] 16008#0: *3 connect() to unix:/tmp/fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.2
.113, server: mysite.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/fpm.sock:", host: "mysite.com"
Другой вопрос:
по пути /tmp/fpm.sock, этого fpm.sock у меня нет.
locate fpm.sock тоже ничего не возвращает, хотя php-fpm запущен.
Может в этом проблема, из-за чего дефолтный конфиг не работает?
Отправлено спустя 18 минут 8 секунд:
Ошибся чуток, это ошибка из лога сайта.
Вот кусок из лог нжинкса, после рестарта:
Код: Выделить всё
2015/07/07 10:02:41 [notice] 16029#0: signal 15 (SIGTERM) received, exiting
2015/07/07 10:02:41 [notice] 16031#0: exiting
2015/07/07 10:02:41 [notice] 16030#0: exiting
2015/07/07 10:02:41 [notice] 16029#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16033#0: exiting
2015/07/07 10:02:41 [notice] 16029#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16029#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16029#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16032#0: exiting
2015/07/07 10:02:41 [notice] 16031#0: exit
2015/07/07 10:02:41 [notice] 16033#0: exit
2015/07/07 10:02:41 [notice] 16030#0: exit
2015/07/07 10:02:41 [notice] 16032#0: exit
2015/07/07 10:02:41 [notice] 16029#0: signal 20 (SIGCHLD) received
2015/07/07 10:02:41 [notice] 16029#0: worker process 16033 exited with code 0
2015/07/07 10:02:41 [notice] 16029#0: worker process 16030 exited with code 0
2015/07/07 10:02:41 [notice] 16029#0: signal 20 (SIGCHLD) received
2015/07/07 10:02:41 [notice] 16029#0: worker process 16031 exited with code 0
2015/07/07 10:02:41 [notice] 16029#0: signal 20 (SIGCHLD) received
2015/07/07 10:02:41 [notice] 16029#0: worker process 16032 exited with code 0
2015/07/07 10:02:41 [notice] 16029#0: exit
2015/07/07 10:02:41 [notice] 16726#0: using the "kqueue" event method
2015/07/07 10:02:41 [notice] 16726#0: nginx/1.8.0
2015/07/07 10:02:41 [notice] 16726#0: OS: FreeBSD 10.0-RELEASE
2015/07/07 10:02:41 [notice] 16726#0: kern.osreldate: 1000510, built on 1001000
2015/07/07 10:02:41 [notice] 16726#0: hw.ncpu: 4
2015/07/07 10:02:41 [notice] 16726#0: net.inet.tcp.sendspace: 32768
2015/07/07 10:02:41 [notice] 16726#0: kern.ipc.somaxconn: 1280
2015/07/07 10:02:41 [notice] 16726#0: getrlimit(RLIMIT_NOFILE): 58239:58239
2015/07/07 10:02:41 [notice] 16727#0: start worker processes
2015/07/07 10:02:41 [notice] 16727#0: start worker process 16728
2015/07/07 10:02:41 [notice] 16727#0: start worker process 16729
2015/07/07 10:02:41 [notice] 16727#0: start worker process 16730
2015/07/07 10:02:41 [notice] 16727#0: start worker process 16731
2015/07/07 10:02:41 [notice] 16727#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16727#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16727#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16727#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16727#0: signal 23 (SIGIO) received
2015/07/07 10:02:41 [notice] 16727#0: signal 23 (SIGIO) received
Отправлено спустя 2 часа 19 минут 38 секунд:
В ходе экспериментов, удалось добиться того, чтобы ошибки не было.
Сейчас просто белый экран. Ошибок ни в нжинкс ни фпм нет.
Конфиг такой:
Код: Выделить всё
server {
listen 80;
server_name narco.dn.ua;
access_log /var/log/nginx/www.mysite.com_log;
error_log /var/log/nginx/www.mysite.com-error_log;
set $root_path '/usr/local/www/data/mysite.com';
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$
access_log off;
log_not_found off;
expires max;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~ /\. {
deny all;
}
}
php-fpm.conf
Код: Выделить всё
user = www
group = www
listen = /tmp/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660
Белый экран и в админке и в основном сайте.
Что еще можно подумать?
Переделка htaccess в nginx
Добавлено: 2015-07-09 10:06:45
eFusion
Разобрался. Как обычно разработчики радуют своими официальными конфигами.
Вот, конфиг nginx для wordpress 4.2.2 - может кому пригодится:
Код: Выделить всё
server {
listen 80;
server_name mysite.com;
access_log /var/log/nginx/www.mysite.com_log;
error_log /var/log/nginx/www.mysite.com-error_log;
root /usr/local/www/data/mysite.com;
index index.php;
gzip on;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/ja
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$
access_log off;
log_not_found off;
expires max;
}
location / {
try_files $uri $uri/ @wordpress;
index index.php index.html index.htm;
}
location ~ \.php$ {
try_files $uri @wordpress;
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location @wordpress {
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
}