nginx中配置php

nginx中配置php

首先从外到内依次是:http, server, localtion
并且是依次继承的关系。

一个server就是一个服务,可设置独立的端口,域名,及其他配置,如果设置不同的
端口了,master进程就会监听这个端口了。

同一个server里面有多个location,这些location不是平行关系,是匹配关系,不能相互继承。

在同一个server里面,我们可以把 root和index的设置 放到location之外。

针对每个server来配置 access_log, error_log.

针对初始页面,由于nginx有提供提示页面,在50x.html, index.html的location中定义一下root到nginx
原本的页面。

一般会在http中来include各个server。

可以设置worker_processes个数,并由master管理。

注意if后面要有空格。

重定向错误页面到 
	error_page   500 502 503 504  /50x.html;
	紧接着拦截 /50x.html
	location = /50x.html {
	    root   /usr/share/nginx/html;
	}

当直接访问域名或ip时,提示一个欢迎页,如果没有设置,会提示 403,
需要蒂尼单独的root,默认去到/usr/share/nginx/html/index.html
	location = / {
        root   /usr/share/nginx/html;
    }

创建 
	/etc/nginx/log/leba.access.log
	/etc/nginx/log/leba.error.log

403错误
	防火墙
	SELinux
	欢迎页未配置


nginx.conf文件

	user  nginx;
	worker_processes  1;
	pid  /var/run/nginx.pid;

	events {
	    worker_connections  1024;
	}

	http {
	    include /etc/nginx/mime.types;
	    default_type  application/octet-stream;

	    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
	                      '$status $body_bytes_sent "$http_referer" '
	                      '"$http_user_agent" "$http_x_forwarded_for"';

	    sendfile        on;
	    keepalive_timeout  65;

	    include /etc/nginx/conf.d/*.conf;
	}

conf.d/default.conf文件

	server {
	    listen       80;
	    server_name  leba.test;

	    access_log  /etc/nginx/log/leba.access.log  main;
	    error_log   /etc/nginx/log/leba.error.log   warn;

	    index  index.html index.htm index.php;
	    root   /mydata/data;

	    location = / {
	        root   /usr/share/nginx/html;
	    }

	    error_page   500 502 503 504  /50x.html;
	    location = /50x.html {
	        root   /usr/share/nginx/html;
	    }

	    location /dc_leba_new/lb_api/public/ {
	        if (!-e $request_filename){
	            rewrite  ^/dc_leba_new/lb_api/public/(.*)$  /dc_leba_new/lb_api/public/index.php?s=/$1  last;
	        }
	    }
	    
	    location ~ \.php$ {
	        fastcgi_pass   127.0.0.1:9000;
	        fastcgi_index  index.php;
	        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
	        include        fastcgi_params;
	    }
	}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ngx_php功能是为nginx模块嵌入php脚本语言。别名为php-nginx-module。 特性 * 支持加载php.ini配置文件 * 支持原生php的全局变量$_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_SESSION... * 支持运行php代码与文件 * 支持RFC 1867文件上传协议 * 支持php错误输出 * 支持加载与运行PECL扩展 * 支持nginx的API在php调用 环境 - PHP 5.3.*     PHP 5.4.*     PHP 5.5.*     PHP 5.6.* - nginx-1.4.7     nginx-1.6.3     nginx-1.8.1     nginx-1.9.15 安装 git clone https://github.com/rryqszq4/ngx_php.git wget 'http://nginx.org/download/nginx-1.6.3.tar.gz' tar -zxvf nginx-1.6.3.tar.gz cd nginx-1.6.3 export PHP_BIN=/path/to/php/bin export PHP_INC=/path/to/php/include/php export PHP_LIB=/path/to/php/lib ./configure --user=www --group=www \             --prefix=/path/to/nginx \             --with-ld-opt="-Wl,-rpath,$PHP_LIB" \             --add-module=/path/to/ngx_php/dev/ngx_devel_kit \             --add-module=/path/to/ngx_php 概要 user www www; worker_processes  4; events {     worker_connections  1024; } http {     include       mime.types;     default_type  application/octet-stream;     keepalive_timeout  65;          client_max_body_size 10m;        client_body_buffer_size 4096k;     php_ini_path /usr/local/php/etc/php.ini;     server {         listen       80;         server_name  localhost;              location /php {             content_by_php '                 echo "hello ngx_php";             ';         }     } } 标签:ngxphp

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值