nginx搭建php项目

以dokuwiki为例

安装nginx

安装php5-fpm

sudo apt-get install php5-fpm

添加php项目配置:

  1. 将/etc/nginx/sites-enabled/下的默认配置文件default复制一份儿,改名为dokuwiki:
    cp /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/dokuwiki
  2. 修改/etc/nginx/sites-enabled/dokuwiki
    vim /etc/nginx/sites-enabled/dokuwiki
    修改配置文件如下:
server {
        listen 80;#监听端口
        #listen [::]:80 ipv6only=on;#这条我不明白是干什么的,但是注释掉之后nginx才能正常启动

        root /var/www/html/dokuwiki;#设置项目根目录
        index index.php index.html;#默认页面,首页

        # Make site accessible from http://localhost/
        server_name localhost;#监听域名

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
        location ~ \.php$ {
                #root /var/www/html/dokuwiki; #指定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 $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
  }
  1. 修改/etc/nginx/nginx.conf
    vim /etc/nginx/nginx.conf
    在/etc/nginx/nginx.conf中的
    http {}
    块中添加:
    include /etc/nginx/sites-enabled/dokuwiki;
    这样将刚刚的配置添加进来
  2. 查看是否配置成功
    nginx -t
    如果显示nginx.conf test successfully就说明配置成功了
  3. 使配置生效
    nginx -s reload
    这样就可以打开localhost/install.php设置dokuwiki信息了

centos中使用nginx搭建php项目

yum install php5-fpm
提示找不到包,于是用google找到了centos上使用nginx搭建php项目的方法:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-6

你可能感兴趣的:(nginx搭建php项目)