博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LNMP]Nginx解析php与代理
阅读量:6978 次
发布时间:2019-06-27

本文共 2089 字,大约阅读时间需要 6 分钟。

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代理

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
,如需转载请自行联系原作者
你可能感兴趣的文章
Linux下分割与合并文件的方法
查看>>
安全攻防实战:使用winlogonhack获取系统密码
查看>>
AD RMS高可用(三)部署RMS根群集服务器
查看>>
5.1 python的缩进
查看>>
瀚思首发三款产品 推动大数据安全战略布局
查看>>
全“芯”关注用户需求 AMD“超轻薄笔记本”杀出重围
查看>>
自定义通知与系统通知的学习(详解)
查看>>
软考新思维--2017年上半年信息系统项目管理师上午试题分析与答案(试题16-20题)...
查看>>
C#编码简单性之语义篇(如何编写简短的C#代码,随时更新)
查看>>
使用sudo进入root权限,以及防止root密码被恶意篡改
查看>>
Android 多媒体综述
查看>>
route命令相关整理
查看>>
关于VS2012如何安装Windows Phone Toolkit
查看>>
Forefront for OCS2007之部署
查看>>
IBM Thinkpad T43-44U 升级到 2G 内存后少了 66M
查看>>
【No.1_sizeof与strlen】
查看>>
SMO学习笔记(二)——还原(恢复)篇之完整恢复
查看>>
Windows Server 2003 AD升级到Windows Server 2008 AD的方法及详细步骤
查看>>
设置php-fpm使用socket文件
查看>>
用 Label 控制 Service 的位置 - 每天5分钟玩转 Docker 容器技术(106)
查看>>