今天用ubuntu安装nginx+php5+mysql+fastcgi发现的问题

我不明白 发布于 2013/10/16 16:04
阅读 1K+
收藏 0

今天想学习一下WEB服务器的架设 

用的是 乌班图 12.04的版本

先安装了 mysql数据库之后安装了 nginx  php5   spawn-fcgi   

修改了相应的配置文件以后开始 做php-cgi的运营 但是问题出现了 执行完下面的语句以后

sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

提示spawn-fcgi:invalid port: 0  不知道什么原因 是因为我的配置文件有问题 还是 怎么的?

这是default文件的配置

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /var/www;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        # Only for nginx-naxsi : process denied requests
        #location /RequestDenied {
                # For example, return an error code
                #return 418;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /usr/share/nginx/www;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
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_FILENAME         $request_filename;
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;

fastcgi_param   HTTPS                   $https;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param   REDIRECT_STATUS         200;
fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;

另外我想请教一下各位高手,spawn-fcgi和php5-fpm都是php-cgi的进程管理器 是不是安装其中之一 就可以的 而不需要两个同时都安装吧?

加载中
0
eechen
eechen
PHP现在已经有了自己的fastcgi管理器php-fpm,不需要spawn-fcgi了。

安装:
sudo apt-get install php5-fpm
服务管理:
sudo service php5-fpm {start|stop|status|restart|reload|force-reload}
配置文件:
/etc/php5/fpm/php-fpm.conf
/etc/php5/fpm/pool.d/www.conf

我不明白
我不明白
那也就是说 我直接在安装 php5的时候 后面带上 php5-fpm就行了? sudo apt-get install php5 php5-fpm这样? 安装好以后 我直接 执行sudo service php5-fpm start完事了?
0
eechen
eechen
location ~ \.php$ {
    root           /etc/nginx/sites-enabled/default;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /etc/nginx/sites-enabled/default$fastcgi_script_name;
    include        fastcgi_params;
}

回复 @我不明白 : 同时还要注意Nginx里的PHP解析配置。
z
zx32342342
关于root这一项, nginx内置变量$document_root可以好好用下, 比如: server { root /a/a location ~ \.php${ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } N多server的时候 这一块可以直接放include的文件内
返回顶部
顶部