nginx php,nginx


操作都在root权限下进行

1.安装nginx

apt-get install nginx

配置文件默认安装位置:

conf: /etc/nginx/nginx.conf

bin:/usr/sbin/nginx

vhost: /etc/nginx/sites-enable/default

cgi-params: /etc/nginx/fastcgi-params


2.建立一个vitual server,修改配置文件

vi /etc/nginx/sites-enabled/default

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

    root /usr/share/nginx/www;
    index index.php
    #index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name 121.188.23.198;#供访问的公网IP

    access_log /var/log/nginx/home.ucenter.access.log;
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }

    #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;
    #    include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny all;
    #}
}

3,安装php-cgi

apt-get install php5-cgi

配置文件默认安装位置:

php-cgi: /usr/bin/php-cgi

php5-cgi: /usr/bin/php5-cgi

cgi config: /etc/php5/cgi/php.ini

修改php.ini文件的cgi.fix_pathinfo数据为1,默认为0 cgi.fix_pathinfo=1; 这样php-cgi方能正常使用SCRIPT_FILENAME这个变量


4,安装spawn-fcgi spawn-fcgi是lighttpd的一个用来控制php-cgi的工具.

如果系统没有安装GCC编译环境,刚需要在安装lighttpd之前要安装build-essential工具包,执行以下命令

  apt-get install build-essential

  wget http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz

  tar -xvf lighttpd-1.4.19.tar.gz

  cd lighttpd-1.4.19/

  apt-get install libpcre3-dev

  ./configure --without-zlib --without-bzip2

  make

  cp src/spawn-fcgi /usr/local/bin/spawn-fcgi

这样cgi控制器就安装完成.


5, 启动fast_cgi:

  spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php-cgi

  注意:ip,端口与nginx服务器中的cgi-pass要对应. -C表示打开几个cgi进程

  启动nginx

   /etc/init.d/nginx start

没有出错信息,则说明配置成功了

将spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php-cgi

  /etc/init.d/nginx start 写入/etc/rc.local中,机器开机启动时能自动加载该服务

6,测试

    cd /usr/share/nginx/www

    vi index.php

    <?php

       echo phpinfo();

    ?>

    保存退出。/etc/init.d/nginx restart,在浏览器输入栏输入121.188.23.198,就可看到phpinfo显示的信息,每次修改完配置文件,都要/etc/init.d/nginx restart

相关内容

    暂无相关文章