[LNMP]Nginx解析php与代理

PHP解析

1、编辑配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@plinuxos ~] # vi /usr/local/nginx/conf/vhost/default.conf
server
{
     listen 80 default_server;  
     server_name aaa.com;
     index index.html index.htm index.php;
     root  /data/wwwroot/default ;
     access_log  /tmp/default .log juispan;
     location ~ \.php$
     {
         include fastcgi_params;
         fastcgi_pass unix: /tmp/php-fcgi .sock;   ##用来指定php-fpm监听的地址或者socket
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME  /data/wwwroot/default $fastcgi_script_name;
     }
}

要确保fcgi.sock路径存在:astcgi_pass unix:/tmp/php-fcgi.sock;路径不对,访问错误会报502错误。

2、检查与重载

1
2
3
4
[root@plinuxos ~] # /usr/local/nginx/sbin/nginx -t
nginx: the configuration  file  /usr/local/nginx/conf/nginx .conf syntax is ok
nginx: configuration  file  /usr/local/nginx/conf/nginx .conf  test  is successful
[root@plinuxos ~] # /usr/local/nginx/sbin/nginx -s reload

3、测试效果

1
2
3
4
5
6
7
8
9
10
11
[root@plinuxos ~] # vi /data/wwwroot/default/1.php
<?php
phpinfo();
?>
[root@plinuxos ~] # curl -x127.0.0.1:80 aaa.com/1.php -I
HTTP /1 .1 200 OK
Server: nginx /1 .12.1
Date: Tue, 15 Aug 2017 00:55:39 GMT
Content-Type: text /html ; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP /5 .6.30    ##php 5.6.30


Nginx代理

wKiom1mSSEah3F7PAAAifeJ-xts815.png

1、创建配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@plinuxos ~] # cd /usr/local/nginx/conf/vhost
[root@plinuxos vhost] # vi /usr/local/nginx/conf/vhost/proxy.conf
server
{
    listen 80;
    server_name baidu.com;
    location /
    {
        proxy_pass http: //111 .13.101.208/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

2、检查与重载

1
2
3
4
[root@plinuxos ~] # /usr/local/nginx/sbin/nginx -t
nginx: the configuration  file  /usr/local/nginx/conf/nginx .conf syntax is ok
nginx: configuration  file  /usr/local/nginx/conf/nginx .conf  test  is successful
[root@plinuxos ~] # /usr/local/nginx/sbin/nginx -s reload

3、测试效果

1
2
3
4
[root@plinuxos vhost] # curl -x127.0.0.1:80 baidu.com
<html>
<meta http-equiv= "refresh"  content= "0;url=http://www.baidu.com/" >
< /html >














本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1956295 ,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值