-
Website
http://blog.kovyrin.net -
Original page
http://blog.kovyrin.net/2006/05/30/nginx-php-fastcgi-howto/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
for you health
3 comments · 1 points
-
jamiew
1 comment · 6 points
-
qu1j0t3
1 comment · 1 points
-
mkv to dvd
1 comment · 1 points
-
Scoundrel
9 comments · 1 points
-
-
Popular Threads
1. PHP запущенный с ключем "-b" время от времени незаметно падает. Как решить не знаю.
2. Для нормальной работы скриптов типа "Dumper" или других длинных скриптов можно использовать
fastcgi_read_timeout 10m; например.
Макс Тараненко.
Я с ним (nginx) первый раз столкнулся. Замучился уже с настройкой rewrite+php (fastcgi). Могли бы показать?
Мне надо сдлелать "разброску" по поддоменам (это я уже решил) так, чтоб это нормально работало с PHP (это и есть проблема).
Проблема заключается в том, что в ответ на http://SOME.localhost.ru/ я получаю то, что требуется, а в ответ на http://SOME.localhost.ru/index.php получаю сообщение "No input file specified", т.е. я неверно настроил реврайтинг.
Вот мой конфиг:
server {
listen 127.0.0.1:80;
server_name localhost.ru *.localhost.ru
location / {
root /home/www/data/public_html/;
index index.php index.html index.htm;
# перенаправление YYY.XXX.localhost.ru на XXX.localhost.ru
if ($http_host ~ ^.+\.[^\.]+\.localhost\.ru.*$) {
rewrite ^(.*)$ $http_host$1;
rewrite ^.*\.([^\.]+)\.localhost\.ru(.*)$ http://$1.localhost.ru$2 permanent;
break;
}
# отображение XXX.localhost.ru в пользовательские папки XXX
if ($http_host ~ ^.*\.localhost\.ru.*$) {
rewrite ^(.*)$ $http_host$1;
rewrite ^(.+)\.localhost\.ru(.*)$ /ub$2 break;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/flybb/data/public_html$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;
}
}
Осмелюсь задать вопрос и расчитываю на помощь, так как не у кого больше спросить :(
Есть виртуальный сервер, в котором нужно прописать alias - выглядит это так:
location / {
root /www/www2/www3/forum ;
index index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php4.3.0-fcgi.sock;
#fastcgi_pass 127.0.0.1:9090;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/www2/www3/forum$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
}
и нужно добавить алиас который будет обрабатываться PHP-шником:
location /gallery/ {
alias /www/www2/www3/4images/;
index index.php;
}
И вот не получается :( Статику из алиаса отдаёт, а ПХП скрипты нет :(
Подскажите что нужно сделать. Заранее благодарен.
Вид сайта должен получиться таким:
http://www.site.com/
а с алисом
http://www.site.com/gallery/
Подскажите в чем может быть дело.
1) Попатчить его
2) Найти, как он это делает и попытаться передать ему этот IP нужным образом.
But on that note...
The nginx site mentions "quick log rotation" but I can't seem to find anything on it. I pipe apache and lighttpd logs through cronolog right now. Can nginx do that and if so, what would the syntax be?
Nginx community is primarily Russian speaking now, so it can be hard to ask community some questions...
But don't think, that there is no English-speaking community! It is there, but it is not so organized yet as Russian one is, so there is no active newsgroups or mailing lists dedicated to nginx. But you can as me here or via IM and I'll try to answer within my knowledge of nginx and English ;-)
Regards, Clau
Regards, Clau
Переходим с Apache на Nginx, производительность возросла в Х-раз, ресурсов жрет ровно в 2 раза меньше, в общем все летает, но есть одна проблемка из-за которой перейти не можем.
В Apache .htaccess есть правило
RewriteCond %{REMOTE_ADDR} ^XXX.XXX.XXX.XXX
RewriteRule ^(.*)folder/([0-9]*).gif$ http://othersite.com//$2.gif
RewriteCond %{REMOTE_ADDR} !^XXX.XXX.XXX.XXX
RewriteRule ^(.*)folder/([0-9]*).gif$ http://mainsite.com//$2.gif
Помогите написать такие правила для Nginx
Спасибо.
"No input file specified."
Could anybody help me ?
Jeremy.
That error means that the path at:
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
Doesn't point to your php files.
Regards
строчку
EX="/bin/su -m -c \"$PHPFCGI -q -b $FCGIADDR:$FCGIPORT\" $USERID"
надо заменить на
EX="/bin/su -m $USERID -c \"$PHPFCGI -q -b $FCGIADDR:$FCGIPORT\""
установил FCGI_WEB_SERVER_ADDRS="127.0.0.1" и заработало.
Relative path "html$fastcgi_script_name;" doesn't work...but...Absoulte path "/usr/local/nginx/html$fastcgi_script_name;" works
Regards
Кто-нить смог решить проблему использования файлов *.htc c этим сервером?
Кто хочет по настоящему "устать" - вперед...
Интересно, это вообще реально?
I installed nginx and php as you said but when I try to open a php file it displays:
The page you are looking for is temporarily unavailable.
Please try again later.
Can you help me with that?
Thanks
Очепяточку поправьте "версия примера нвходится".
I have some problems with rewrite rules.
First, excuse me for my bad English...
I have an htacces from Apache like :
RewriteEngine on
DirectoryIndex gabarit.php?contenu=itineraire
RewriteCond %{REQUEST_URI} !temporaire\.htm
RewriteRule ^([a-z-]*)\.htm$ gabarit\.php?contenu=$1 [L]
RewriteRule ^galeries/$ gabarit\.php?contenu=accueil-galerie [L]
RewriteRule ^galeries/([0-9]*)/([0-9]*)\.htm$ gabarit\.php?contenu=detail-galerie&categorie=$1&galerie=$2 [L]
I want to translate it to Nginx rewrite rules
Here, a piece of my conf that doesn't work :
location /
{
index gabarit.php;
root /home/work/jnbarak/current;
rewrite ^/(.*)\.htm$ /gabarit.php?contenu=$1 last; # it works !
rewrite ^/galeries/$ /gabarit\.php?contenu=accueil-galerie? last; # it doesn't work !
rewrite ^/galeries/([0-9]*)/([0-9]*)\.htm$ /gabarit\.php?contenu=detail-galerie&categorie=$1&galerie=$2 last; # it doesn't work !
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/work/jnbarak/current$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi.conf;
}
When I try :
http://my_domain.tld/galeries/
I have the error :
"No input file specified."
When I try :
http://my_domain.tld/galeries/1/5.htm
I am redirect to :
http://my_domain.tld/gabarit.php?contenu=accuei...
Some one can help me please ?
Good job with this blog and long life to Nginx !
Jeremy.
I want to deleguate the rewrite rules of my vhosts to an other person who hasn't root privileges.
With Apache, it's possible to declare a dynamic configuration file htaccess in each web repository. And it's not necessary to restart the server when file has changed.
Is it possible to do it with Nginx ?
Best regards.
Jérémy.
> 1. PHP запущенный с ключем “-b” время от времени незаметно падает. Как решить не знаю.
Сталкнулся с такой же проблемой. Удалось решить?
> ## number of request before php-process
> will be restarted
> PHP_FCGI_MAX_REQUESTS=1000
Вот оно - решение :-) Падает он незаметно именно после 1000 запросов в данном случае. Потому надо перезапускать или найти как отключить (может быть при 0 оно не будет его гасить).
There's a question I have to ask.
My php scripts are in /var/www/my/,so I created a alias for them.
Content:
location /my/
{
alias /vaw/www/my/;
}
After running, I noted that the html files can be excuted properly,but the php files can not be found and excuted.Text from the server is "No input file specified".Please tell how to set this kind of alias.
Forgive my pool English.
By the way,the php scritps in /var/ww/html(my root document) can be excuted properly.
Thanks! Great post. Unfortunately, I'm seeing a nginx error: 2007/10/15 17:32:17 [error] 5093#0: *3381 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 69.2.2.2, server: www.forum.server.com, URL: "/index.php", upstream: "fastcgi://127.0.0.1:8888", host: "www.forum.server.com"
I installed the latest php, v2.2.0
Ideas much appreciated,
Larry
Solved the problem by enabling logging on php (see php.ini) and then sending error out to a file. (See last line of the php start-up script, above.) The error message from php was that FCGI_WEB_SERVER_ADDRS was not set correctly.
Adding FCGI_WEB_SERVER_ADDRS="127.0.0.1" to the start-up script solved the problem.
Also note that the php-cgi binary should be used, not the regular php binary.
Regards,
Larry
все вроде бы работает, но есть вопрос такой:
у меня 5виртуальных хостов
но пхп работает только если прописать путь аналогичный
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
где этот путь является путем до одно из хостов. т.е. если написать путь /корень/хост1
все хосты расположены так
корень - хост1
корень - хост2
и т.п.
если задать в параметре путь к корню то пхп пытается обработать тот файл что лежит в нем...
thanks
There’s a question I have to ask.
My php scripts are in /var/www/my/,so I created a alias for them.
Content:
location /my/
{
alias /vaw/www/my/;
}
After running, I noted that the html files can be excuted properly,but the php files can not be found and excuted.Text from the server is “No input file specified”.Please tell how to set this kind of alias.
Forgive my pool English.
By the way,the php scritps in /var/ww/html(my root document) can be excuted properly.
fastcgi_param SCRIPT_FILENAME
points to the right directory where your script is located. this solved the issue for me!
Thank you for posting this. But I think it is a bit complex.
1. What if I want to run PHP through nginx but without fastcgi (which is way too painful for anything beyond the basic PHP functionality).
2. Also, in my Apache the "DefaultType" is PHP. So I have many programs without a ".php" configuration. In your example config, you tell nginx to serve php files based on the file-extension (.php). Can I tell nginx to serve php files based on "Type" and not the "File Extension"?
Thanks!
Скрипт запуска Fast CGI (который представлен в этой статье) - не полный, у него отсутствует нижняя часть!
Подскажите пожалуйста , где взять этот скрипт полностью?
Большое спасибо
Если не затруднит, подскажите пожалуйста.. имеет-ли смысл играть с директивами буферизации (proxy_buffers, proxy_buffer_size) при проксировании на fastcgi.. ?
Заранее благодарю..
location /gallery2-base/ {
alias /usr/share/gallery2/;
index index.php index.html index.htm;
}
location ~ /gallery2-base/.*\.php$ {
if ($fastcgi_script_name ~ /gallery2-base(/.*\.php)$) {
set $valid_fastcgi_script_name $1;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/gallery2$valid_fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
очень полезно
Есть ли у ngnix какая - нид возможность отключить будеризацию пост запросос и сразу направлять их php