淘先锋技术网

首页 1 2 3 4 5 6 7

1.安装nginx

    yum install epel-release      #安装依赖

    yum install nginx

2.在/etc/nginx/conf.d/目录下新建配置文件   vhosts.conf

    新增以下配置    

server {

 

listen 80; #监听80端口

 

server_name mpm.lzyco.com;

 

location / {

 

        root /var/www/www.mpm2.lzy; #网站的根目录

 

        index index.html index.htm; #默认首页文件名

 

    }

 

}

 

server {

 

listen 9080;

 

server_name api-mpm.lzyco.com; #虚拟主机名,可以为域名或ip地址

 

root /var/www/api.mpm2.lzy; #网站的根目录

 

index index.php index.htm; #默认首页文件名

 

 

location ~ \.php {

        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_split_path_info ^(.+\.php)(.*)$;

        fastcgi_param PATH_INFO $fastcgi_path_info;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include fastcgi_params;

    }

}

 

server {

 

listen 9081;

 

server_name fs-mpm.lzyco.com; #虚拟主机名,可以为域名或ip地址

 

root /var/www/fs.mpm2.lzy; #网站的根目录

 

index index.php index.htm; #默认首页文件名

 

add_header   Access-Control-Allow-Origin   '*' ;

 

location ~ \.php {

        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_split_path_info ^(.+\.php)(.*)$;

        fastcgi_param PATH_INFO $fastcgi_path_info;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include fastcgi_params;

    }

 

}

systemctl start nginx

3.安装php-fpm

    yum install php70w-fpm

4.配置PHP处理器

vim /etc/php.ini

查找cgi.fix_pathinfo

将 ;cgi.fix_pathinfo=1改为cgi.fix_pathinfo=0

5.配置www.conf

vim /etc/php-fpm.d/www.conf

user = nobody

group = nobody

改为

user = nginx

group = nginx

前提是已经创建了nginx用户和nginx组。

 

6.启动php-fpm

systemctl start php-fpm

7.设置php-fpm开机启动

systemctl enable php-fpm

8.性能优化

vim /etc/php-fpm.d/www.conf

进程数优化

pm = dynamic

pm.max_children = 300

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

最大请求数优化

pm.max_requests = 10240