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;
	    }
	}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值