[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 ,如需转载请自行联系原作者
相关文章
|
16天前
|
运维 应用服务中间件 Linux
LNMP详解(十三)——Nginx子页面详解
LNMP详解(十三)——Nginx子页面详解
14 3
|
20天前
|
PHP 项目管理 开发者
深入解析PHP的命名空间和自动加载机制
【4月更文挑战第4天】 在PHP的编程世界中,命名空间和自动加载机制是构建大型应用程序时不可或缺的工具。本文将深入探讨这两个概念,揭示它们如何简化代码结构、避免类名冲突以及提高代码维护性。通过对PHP命名空间的由来、作用域和使用方法的细致剖析,以及对自动加载机制工作原理和应用实践的全面讲解,读者将获得有效管理复杂项目中依赖关系的能力。
|
23天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
24 0
|
27天前
|
运维 负载均衡 应用服务中间件
LNMP详解(一)——Nginx详解
LNMP详解(一)——Nginx详解
18 2
|
22天前
|
运维 负载均衡 应用服务中间件
LNMP详解(九)——Nginx虚拟IP实战
LNMP详解(九)——Nginx虚拟IP实战
34 2
|
3天前
|
关系型数据库 MySQL PHP
深入解析PHP中的命名空间
【4月更文挑战第20天】在PHP的编程世界中,命名空间是一个强大的工具,用于解决代码中的名称冲突问题。通过本文的深度解析,我们将探索PHP命名空间的概念、实现原理以及它们如何优雅地帮助我们管理代码库。从基础的定义到高级用法,本篇文章旨在提供一份全面的指南,帮助开发者有效利用命名空间来优化他们的PHP项目结构和可维护性。
|
16天前
|
运维 监控 应用服务中间件
LNMP详解(十四)——Nginx日志详解
LNMP详解(十四)——Nginx日志详解
16 2
|
20天前
|
测试技术 PHP 开发者
PHP 7.4新特性深度解析
【4月更文挑战第4天】 本文将深入探讨PHP 7.4的新特性,包括预加载,数组解构,扩展的箭头函数等。我们将详细解释这些新特性的作用,以及如何在项目中使用它们来提高代码的效率和可读性。
|
26天前
|
运维 应用服务中间件 Linux
LNMP详解(五)——Nginx主配置文件详解
LNMP详解(五)——Nginx主配置文件详解
17 1
|
26天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
23 0