我是靠谱客的博主 害羞耳机,这篇文章主要介绍LNMP、地址重写,现在分享给大家,希望可以做个参考。

LNMP环境搭建
恢复环境
   cd /root/lnmp_soft/nginx-1.17.6/
   [root@proxy nginx-1.17.6]# pwd
   /root/lnmp_soft/nginx-1.17.6
   [root@proxy nginx-1.17.6]# killall nginx
   [root@proxy nginx-1.17.6]# rm -rf /usr/local/nginx/
   make install  安装
   ls /usr/local/nginx  查看目录
安装数据库服务 服务端    客户端  依赖包
  yum -y install mariadb-server
  yum -y install mariadb
  yum -y install mariadb-devel
安装php解析器
   yum -y install php
   yum -y install php-mysql
   yum -y install php-fpm  (服务)     让Nginx具备动态网站解析能力
开启服务,查看端口
   systemctl start mariadb
   systemctl start php-fpm
   netstat -ntulp | grep :3306 数据库默认端口
   netstat -ntulp | grep :9000 PHP端口
修改Nginx配置文件 开启服务 加载配置文件
 先把65到71行注释去掉,69 行保持注释状态
 把fastcgi 的后缀改成 .conf
     sbin/nginx      开启服务
      [root@proxy nginx]# sbin/nginx -s reload  重新加载配置文件
复制PHP文件到Nginx目录下
 cd ~/lnmp_soft/php_scripts/
[root@proxy php_scripts]# cp test.php /usr/local/nginx/html/
访问测试
 curl 192.168.2.5/test.php
<html>
<body>
This is HTML message
</br>
c is bigger</body>
</html>

地址重写
 格式:rewrite   旧 (支持正则)  新     选项
  vim conf/nginx.conf
  rewrite /a.html b/html;-- 42行添加
  sbin/nginx -s reload
  systemctl stop firewalld  关闭防火墙
 访问测试  
1、 rewrite^/a.html$ b/html; 严格匹配a.html
       sbin/nginx -s reload
       systemctl stop firewalld  关闭防火墙
       访问测试  
2、rewrite^/a.html$ b/html redirect ; 
      sbin/nginx -s reload
      访问测试  
3、rewrite / http://www.tmooc.cn;  跳到新网站
      sbin/nginx -s reload
      访问测试  
4、rewrite / (.*)http://www.tmooc.cn/$1; 跳到新网站,保留用户之前访问   的网站内容
     sbin/nginx -s reload
      访问测试  
5、修改配置文件
if ($http_user_agent ~* firefox)  {
 rewrite /(.*) /firefox/$1;
}       $http_user_agent  Nginx内置变量  ~匹配正则   *忽略大小写
 mkdir html/firefox
[root@proxy nginx]# echo "firefox~~~" > html/firefox/abc.html
[root@proxy nginx]# echo "others~~~" > html/abc.html
 sbin/nginx -s reload
     用不同浏览器访问测试  

最后

以上就是害羞耳机最近收集整理的关于LNMP、地址重写的全部内容,更多相关LNMP、地址重写内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部