LNMP环境部署与构建及其地址重写

1.部署LNMP环境

安装nginx基础依赖包
[root@proxy ~]# yum -y install gcc openssl-devel pcre-devel
安装MariaDB
[root@proxy ~]# yum -y install   mariadb   mariadb-server   mariadb-devel
php和php-fpm
[root@proxy ~]# yum -y  install  php   php-mysql
[root@proxy ~]# yum -y  install  php-fpm

2.构建LNMP平台
步骤一: php-fpm配置文件,修改Nginx配置文件并启动服务

[root@proxy etc]# vim /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000            //PHP端口号
pm.max_children = 32                //最大进程数量
pm.start_servers = 15  

[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
 location  ~  \.php$  {
oot           html;
fastcgi_pass   127.0.0.1:9000;    #将请求转发给本机9000端口,PHP解释器
fastcgi_index  index.php;
include        fastcgi.conf;       #加载其他配置文件

步骤二:创建PHP页面

3.地址重写
步骤一:修改配置文件(访问a.html重定向到b.html)

[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
.. ..
server {
        listen       80;
        server_name  localhost;
  rewrite ^/(.*)$  http://www.tmooc.cn/$1; 
} 

实现curl和火狐访问相同链接返回的页面不同)

[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
.. ..
server {
...
location / {
    root   html;
index  index.html index.htm;
}
#这里,~符号代表正则匹配,*符号代表不区分大小写
if ($http_user_agent ~* firefox) {            //识别客户端firefox浏览器
rewrite ^(.*)$  /firefox/$1;
}
}
发布了25 篇原创文章 · 获赞 2 · 访问量 591

猜你喜欢

转载自blog.csdn.net/f5500/article/details/103979278