码迷,mamicode.com
首页 > Web开发 > 详细

centos7 php开发环境安装-Nginx

时间:2019-12-31 14:22:27      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:usr   出现   list   host   doc   rsa   with   安装   var   

 1.Nginx编译安装

tar -zxvf nginx-1.12.2.tar.gz

cd nginx-1.12.2

./configure --user=www --group=www --prefix=/usr/local/nginx/ --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-http_realip_module

make

make install

 

 

2.启动Nginx

cd /usr/local/nginx/sbin

./nginx           #启动     

./nginx -s reload   #重启nginx  

./nginx -s stop     #停止nginx

./nginx -t      #验证配置文件是否正确

3.测试是否安装成功

ps -ef|grep nginx  #测试是否允许   

curl   localhost     #Linux下本地测试 

4.解析php

   重点是创建php-cgi.sock存放目录 不解析时查看是否存在

mkdir /var/run/www/

chown -R www:www /var/run/www

/usr/local/php/sbin/php-fpm
location ~ \.php$ {
    fastcgi_pass unix:/var/run/www/php-cgi.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

5.修改家目录

     打开配置nginx.conf

location / {
            
       root   /home/www/;
       index  index.html index.htm;
 }

6.容易出现的错误  

      ① nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

    解决:  /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

7.配置站点  

     7.1 在安装目录的配置文件目录中新建vhost

     7.2 vhost目录中新建多个站点配置文件

     7.3 站点配置文件内容

 server {

         listen 80;  # 监听端口

         server_name  www.siteA.com siteA.com;    # 站点域名

         root  /home/user/www/blog;              # 站点根目录

         index index.html index.htm index.php;   # 默认导航页

 

         location / {

              # WordPress固定链接URL重写

              if (!-e $request_filename) {

                 rewrite (.*) /index.php;

               }

          }


           # PHP配置

           location ~ \.php$ {

               fastcgi_pass unix:/var/run/php5-fpm.sock;

               fastcgi_index index.php;

              include fastcgi_params;

           }

}

       7.4nginx.conf 中在http {}”部分的末尾添加

 include /etc/nginx/vhost/*.conf;

8.Nginx配置SSL证书

server {
    listen 443;                       
    server_name api.yg.vip;  
    ssl on;  
    root  /home/www/api/public/;              
    index index.php; 

    ssl_certificate /usr/local/nginx/cert/api/3107983_api.ygang.vip.pem;   
    ssl_certificate_key /usr/local/nginx/cert/api/3107983_api.ygang.vip.key;   
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;  
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;  
    ssl_prefer_server_ciphers on;

    
 
    location / {
        # WordPress固定链接URL重写
        if (!-e $request_filename) {
            rewrite (.*) /index.php;
        }
    }
 
    # PHP配置
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/www/php-cgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

centos7 php开发环境安装-Nginx

标签:usr   出现   list   host   doc   rsa   with   安装   var   

原文地址:https://www.cnblogs.com/ddf128/p/12123918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!