Nginx与PHP整合问题

刚买了mac笔记本,积攒了两年的心血,终于狠下心买了,激动的我又狠狠地观赏了一番我的mac book pro,O(∩_∩)O哈哈~

言归正传:这两天没事在mac上装了PHP nginx ,发现mac系统上自带,Apache与PHP7.1虽然已经安装好了,但是傲娇的我就是不想用这么高版本的PHP版本(其实是我的项目在PHP7.1上有很多的不兼容问题,所以我还是回归到PHP5.6)

我发现mac终端很不友好,跟在虚拟机里面装的Linux操作习惯不同,所以我安装了 iTem,这个很强大,我还没有摸索完,先用着。安装PHP brew install php56    | brew install nginx  安装的目录在/usr/local/etc/... 下面。

再启动php56 的时候首先检查有没有已经启动的php-fpm   执行:sudo ps -ef | grep php-fpm 如果有的话执行sudo pkill -INT -o php-fpm 直接杀死进程,简单粗暴。然后启动php-fpm56 

nginx的nginx.conf配置

server{
        listen 80;
        server_name ccp.local.com;
        location / {
            root /var/www/chuchupai;         
	    index index.php index.html index.htm;
  #以下是对url重写 nginx默认是不支持PATH_INFO的需要手动添加
  # 就是在 location ~ \.php(.*)$  中添加
	    if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php?s=$1 last;
                break;
            }

        }
 	
	   location = /favicon.ico { access_log off; log_not_found off;}
	   location = /robots.txt {access_log off; log_not_found off;}
	
        access_log    /var/log/nginx/ccp-access.log main;
        error_log     /var/log/nginx/ccp-error.log;

        sendfile on;    

    	client_max_body_size 100m;

    	location ~ \.php(.*)$ {
    	    root 		/var/www/chuchupai;
    	    fastcgi_pass 	127.0.0.1:9000;
    	    fastcgi_index 	index.php;
    	    fastcgi_param 	SCRIPT_FILENAME $document_root$fastcgi_script_name;
    	    fastcgi_param 	PATH_INFO $1;
    	    fastcgi_param	APP_ENV 'test';
    	    fastcgi_intercept_errors off;
     	    fastcgi_buffer_size 16k;
    	    fastcgi_buffers 4 16k;
    	    fastcgi_connect_timeout	300;
    	    fastcgi_send_timeout	300;
    	    fastcgi_read_timeout	300;
    	    include 		fastcgi_params;
    	}
    	
    	location ~ /\.ht {
    	    deny all;
    	}
	
}

nginx.conf 所在目录 /usr/local/etc/nginx/nginx.conf
增加一个虚拟主机,一帮常用的是在nginx目录下新建一个文件夹,然后里面放的是 *.conf
需要在nginx.conf 中include引一下  如下
include /usr/local/etc/nginx/myhost/*.conf;
其实你也不用再nginx.conf 引入,主要就是为了方便管理虚拟主机,当然你也可以在nginx.conf中直接添加一个server{} 内容如上代码 

当你在nginx.conf中引入了其他的文件,需要重启nginx 而不是 reload

nginx默认不支持PATH_INFO 需要手动添加。如上配置。这样就可以解决thinkPHP框架在nginx下不运行的问题





猜你喜欢

转载自blog.csdn.net/Run_Function_Online/article/details/80059675