banner

[Rule] Rules  [Home] Main Forum  [Portal] Portal  
[Members] Member Listing  [Statistics] Statistics  [Search] Search  [Reading Room] Reading Room 
[Register] Register  
[Login] Loginhttp  | https  ]
 
Forum Index Thảo luận hệ điều hành *nix Biên dịch web server nginx + PHP + FCGI  XML
  [Question]   Biên dịch web server nginx + PHP + FCGI 14/09/2011 10:02:07 (+0700) | #1 | 247087
[Avatar]
vitcon01
Member

[Minus]    0    [Plus]
Joined: 29/04/2009 11:28:21
Messages: 306
Offline
[Profile] [PM]
Em đã tiến hành biên dịch nginx tuy nhiên hiện tại nó chỉ có thể chạy được html, còn php thì bị lỗi 403.

Code:
# ./configure --without-http_autoindex_module --without-http_ssi_module --without-http_userid_module --without-http_auth_basic_module --without-http_geo_module --without-http_empty_gif_modul


Sau đó em biên dịch php-5.3.8
Code:
./configure --with-zlib --with-bz2 --with-curl --with-curlwrappers --enable-exif --enable-ftp --with-gd --with-ldap --enable-mbstring --with-mcrypt --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --enable-soap --enable-sqlite-utf8 --enable-zip --with-openssl


Sau đó em biên dịch spawn-fcgi 1.6.3
Code:
./configure


Tiến hành bật dịch vụ nginx và spawn-fcgi
Code:
[root@localhost init.d]# service fastcgi start
Starting php-cgi: spawn-fcgi: child spawned successfully: PID: 9146
Starting fastcgi: ok
[root@proxy spawn-fcgi-1.6.3]# /usr/local/nginx1/sbin/nginx


Kiêm tra:
Code:
[root@proxy spawn-fcgi-1.6.3]# netstat -an | grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN

[root@proxy spawn-fcgi-1.6.3]# netstat -an | grep :9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN
[root@proxy spawn-fcgi-1.6.3]#

File cấu hình của nginx.conf
Code:
#user  nobody;
worker_processes  1;
user        nginx nginx;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  nixcraft.in www.nixcraft.in;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
      location ~ ^/index.php
        {
                fastcgi_pass 127.0.0.1:9000;
                #CHANGE THIS TO THE PATH TO YOUR WEB ROOT DIRECTORY
                fastcgi_param SCRIPT_FILENAME /var/www/marketdark$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                include fastcgi_params;
        }
        #error_page  404              /404.html;
        # wwwect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
}


File cấu hình của fastcgi_params
Code:
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  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-wwwect
#fastcgi_param  REDIRECT_STATUS    200;

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;


Em cảm ơn!
JK - JH
()()()
LTKT - LTT
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 14/09/2011 10:09:13 (+0700) | #2 | 247089
centos
Member

[Minus]    0    [Plus]
Joined: 28/03/2008 17:13:12
Messages: 219
Offline
[Profile] [PM]
Cho mình xem log báo lỗi của nginx đi bạn, xem nó bảo thế nào?

Theo mình nghĩ là thằng spawn-fcgi của bạn chưa làm việc được với php nên nó trả về lỗi 403. Khi cài đặt spawn xong bạn start lên phải chỉ ra cho spawn biết đường dẫn đến file php-cgi để nó kết nồi về php
spawn-fcgi -a 127.0.0.1 -p 9000 -f /php-path-php-cgi/php5-cgi
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 14/09/2011 11:05:41 (+0700) | #3 | 247098
[Avatar]
conmale
Administrator

Joined: 07/05/2004 23:43:15
Messages: 9353
Location: down under
Offline
[Profile] [PM]
Đã dùng php 5.3.8 thì nên dùng php-fpm đi cho xong. Nên enable "--enable-fpm" trong lúc biên dịch php.

Còn nếu muốn khắc phục lỗi thì luôn luôn kèm logs chớ nói suông lỗi 403 thì có thánh mới giải quyết nổi.
What bringing us together is stronger than what pulling us apart.
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 14/09/2011 12:59:36 (+0700) | #4 | 247113
[Avatar]
vitcon01
Member

[Minus]    0    [Plus]
Joined: 29/04/2009 11:28:21
Messages: 306
Offline
[Profile] [PM]
Đây là log nginx
Code:
[root@proxy php-5.3.8]# tail /usr/local/nginx1/logs/error.log
2011/09/13 23:32:36 [error] 25174#0: *5095 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
2011/09/13 23:32:37 [error] 25174#0: *5095 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
2011/09/13 23:32:37 [error] 25174#0: *5095 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
2011/09/13 23:32:37 [error] 25174#0: *5095 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
2011/09/13 23:32:37 [error] 25174#0: *5095 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
2011/09/13 23:32:37 [error] 25174#0: *5095 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
2011/09/14 00:50:57 [error] 25174#0: *5097 directory index of "/usr/local/nginx1//html/" is forbidden, client: 127.0.0.1, server: nixcraft.in, request: "POST / HTTP/1.1", host: "localhost"
2011/09/14 01:02:04 [error] 25174#0: *5098 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
2011/09/14 01:02:06 [error] 25174#0: *5098 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
2011/09/14 01:02:43 [error] 25174#0: *5098 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
JK - JH
()()()
LTKT - LTT
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 14/09/2011 14:00:17 (+0700) | #5 | 247118
Dpm
Member

[Minus]    0    [Plus]
Joined: 06/04/2009 01:43:30
Messages: 85
Offline
[Profile] [PM]
# ./configure --without-http_autoindex_module --without-http_ssi_module --without-http_userid_module --without-http_auth_basic_module --without-http_geo_module --without-http_empty_gif_modul
2011/09/14 01:02:43 [error] 25174#0: *5098 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 14/09/2011 14:19:28 (+0700) | #6 | 247122
centos
Member

[Minus]    0    [Plus]
Joined: 28/03/2008 17:13:12
Messages: 219
Offline
[Profile] [PM]
mà cài nginx without chi vậy bồ, cứ để ./configure mà phang
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 15/09/2011 12:54:24 (+0700) | #7 | 247170
[Avatar]
vitcon01
Member

[Minus]    0    [Plus]
Joined: 29/04/2009 11:28:21
Messages: 306
Offline
[Profile] [PM]

centos wrote:
mà cài nginx without chi vậy bồ, cứ để ./configure mà phang 

--->sao bồ không yum hay apt-get hay pacman cho nó sương hơn biên dịch làm gì hã bồ.

Code:
# ./configure --without-http_autoindex_module --without-http_ssi_module --without-http_userid_module --without-http_auth_basic_module --without-http_geo_module --without-http_empty_gif_modul
2011/09/14 01:02:43 [error] 25174#0: *5098 directory index of "/usr/local/nginx1//html/" is forbidden, client: 192.168.137.1, server: nixcraft.in, request: "GET / HTTP/1.1", host: "192.168.137.253"


--->cảm ơn bạn, tôi đã thêm module đó, tuy nhiên lỗi vẫn vậy.

Mấu chốt lỗi là chỗ này:
Code:
location / {
             root   html;
             index  index.html index.htm;
         }


tôi tiến hành change như sau

Code:
location / {
             root   html;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
             include        fastcgi_params;

             index  index.html index.htm index.php;
         }

--->thì lỗi không còn hiện ra như trên, tuy nhiên ko hiển thị trang, mà là 1 trang trắng xoá.
JK - JH
()()()
LTKT - LTT
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 19/09/2011 14:17:49 (+0700) | #8 | 247367
centos
Member

[Minus]    0    [Plus]
Joined: 28/03/2008 17:13:12
Messages: 219
Offline
[Profile] [PM]

vitcon01 wrote:

centos wrote:
mà cài nginx without chi vậy bồ, cứ để ./configure mà phang 

--->sao bồ không yum hay apt-get hay pacman cho nó sương hơn biên dịch làm gì hã bồ.

 


Tùy thằng manager nó quyết định việc cài đặt từ source hay tử binarry mà bồ.
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 19/09/2011 15:47:36 (+0700) | #9 | 247374
[Avatar]
quanta
Moderator

Joined: 28/07/2006 14:44:21
Messages: 7265
Location: $ locate `whoami`
Offline
[Profile] [PM]

vitcon01 wrote:

tôi tiến hành change như sau

Code:
location / {
             root   html;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
             include        fastcgi_params;

             index  index.html index.htm index.php;
         }

--->thì lỗi không còn hiện ra như trên, tuy nhiên ko hiển thị trang, mà là 1 trang trắng xoá. 

Em lại quên đưa logs rồi.
Let's build on a great foundation!
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 20/09/2011 02:20:47 (+0700) | #10 | 247396
[Avatar]
.lht.
Member

[Minus]    0    [Plus]
Joined: 26/09/2010 10:06:38
Messages: 75
Location: Inside you
Offline
[Profile] [PM]
listen 80;
server_name nixcraft.in www.nixcraft.in;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location ~ ^/index.php
{
fastcgi_pass 127.0.0.1:9000;
#CHANGE THIS TO THE PATH TO YOUR WEB ROOT DIRECTORY
fastcgi_param SCRIPT_FILENAME /var/www/marketdark$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
#error_page 404 /404.html;
# wwwect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;


Coi qua đoạn config trên của bạn đã thấy 1 số chỗ khó hiểu, bạn chưa config path rõ ràng cho thư mục html và chown cho nó.

Bạn thử sửa lại thế này xem:
1. Tạo 1 thư mục wwwroot và chown cho nó:
Code:
mkdir /home/wwwroot
chown -R nginx:nginx/home/wwwroot


từ đoạn mình quote trên, bạn sửa lại tất cả thành:
Code:
listen       80;
         server_name  nixcraft.in www.nixcraft.in;
         #charset koi8-r;
         #access_log  logs/host.access.log  main;
         location / {
             root   /home/wwwroot;
             index  index.php index.html index.htm;
         }
         #error_page  404              /404.html;
         # wwwect server error pages to the static page /50x.html
         #
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
         root   /home/wwwroot;
         }
         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
         #
         #location ~ \.php$ {
         #    proxy_pass   http://127.0.0.1;
         #}
         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
         #
         location ~ \.php$ {
            #root           /home/wwwroot;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /home/wwwroot$fastcgi_script_name;
            include        fastcgi_params;
        }


Sau đó vào thư mục /home/wwwroot và tạo 1 file php để test và reload nginx (/etc/init.d/nginx reload).
Trash from trash is the place for new good things ~
[Up] [Print Copy]
  [Question]   Biên dịch web server nginx + PHP + FCGI 20/09/2011 08:54:09 (+0700) | #11 | 247408
[Avatar]
panfider
Member

[Minus]    0    [Plus]
Joined: 12/05/2010 01:51:04
Messages: 448
Offline
[Profile] [PM] [Email]
sau không xài httpd mà xài nginx
[Unix] live free or die
[Up] [Print Copy]
[digg] [delicious] [google] [yahoo] [technorati] [reddit] [stumbleupon]
Go to: 
 Users currently in here 
1 Anonymous

Powered by JForum - Extended by HVAOnline
 hvaonline.net  |  hvaforum.net  |  hvazone.net  |  hvanews.net  |  vnhacker.org
1999 - 2013 © v2012|0504|218|