LNMP的搭建 及地址转换
1. LNMP 先安装nginx
yum -y install gcc openssl-devel pcre-devel
wget http://nginx.org/download/nginx-1.12.2.tar.gz (也可配置阿里源用yum安装)
tar -xvf nginx-1.12.2.tar.gz
./configure
make && make install
安装MariaDB php和php-fpm
yum -y install mariadb mariadb-server mariadb-devel php php-mysql php-fpm
/usr/local/nginx/sbin/nginx //启动Nginx服务
systemctl start mariadb //启动服务器并设开机自启
systemctl start php-fpm //启动服务并设开机自启
修改Nginx配置文件并启动服务 开启php功能
vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
#设置默认首页为index.php,当用户在浏览器地址栏中只写域名或IP,不说访问什么页面时,服务器会把默认首页index.php返回给用户
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000; #将请求转发给本机9000端口,PHP解释器
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf; #加载其他配置文件(改)
}
/usr/local/nginx/sbin/nginx -s reload 重启nginx
2. 地址重写
关于Nginx服务器的地址重写,主要用到的配置参数是rewrite
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
rewrite /a.html /b.html; 访问a.html转发到b.html 但域名还是a.html rewrite /a.html /b.html redirect; 多在后面加个redirect 地址转发后域名也会变成b.html
location / {
root html;
index index.html index.htm;
}
}
echo "BB" > /usr/local/nginx/html/b.html 在b.html里写入数据
/usr/local/nginx/sbin/nginx -s reload 重启nginx
firefox http://192.168.4.5/a.html 客户端测试
3. 修改配置文件(访问本机IP 192.168.17.10的请求重定向至www.tmooc.cn)
以上面配置文件为例把 rewrite后面改为以下条件即可:
rewrite ^/ http://www.tmooc.cn/;
/usr/local/nginx/sbin/nginx -s reload 重新加载配置文件
firefox http://192.168.4.5 客户端测试
4. 修改配置文件(访问192.168.17.10/下面子页面,重定向至www.tmooc.cn/下相同的页面)
以上面配置文件为例把 rewrite后面改为以下条件即可:
rewrite ^/(.*)$ http://www.tmooc.cn/$1;
/usr/local/nginx/sbin/nginx -s reload 重新加载配置文件
firefox http://192.168.4.5 firefox http://192.168.4.5/test 客户端测试
5. 修改配置文件(实现curl和火狐访问相同链接返回的页面不同)
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
#这里,~符号代表正则匹配,*符号代表不区分大小写
if ($http_user_agent ~* firefox) { //识别客户端firefox浏览器
rewrite ^(.*)$ /firefox/$1;
}
}
创建网页目录以及对应的页面文件:
echo "I am Normal page" > /usr/local/nginx/html/test.html
mkdir -p /usr/local/nginx/html/firefox/
echo "firefox page" > /usr/local/nginx/html/firefox/test.html
/usr/local/nginx/sbin/nginx -s reload 重新加载配置文件
firefox http://192.168.4.5/test.html 测试
curl http://192.168.4.5/test.html
最新文章
- oracle异常(-)
- Android 的 AlarmManager 和 wakeLock联合使用
- Eclipse启动时卡死解决方法
- 轻量级远程调用框架-Hessian学习笔记-Demo实现
- 剑指OFFER之树的子结构(九度OJ1520)
- linux下显卡信息的查看
- 如何让asp.net mvc 直接运行mobile页面
- VC中遍历进程并获取进程信息
- S2S:分享出的营销机遇
- (Relax njuptoj)1009 数的计算(DP)
- 开源 自由 java CMS - FreeCMS1.9 评论管理
- .NET Core log4net 使用
- @Autowired标签与 @Resource标签 的区别
- 在Eclipse中关联Android API源码
- ASP.NET中HttpContext.Cache的使用
- android 之ViewStub
- webpack.config.js配置遇到Error: Cannot find module '@babel/core'&;&;Cannot find module '@babel/plugin-transform-react-jsx' 问题
- 20155325 Exp9 Web安全基础
- python 直方图hist
- 基于matplotlib的数据可视化 - 三维曲面图gca
热门文章
- 002.Kubernetes简单入门实例
- PHP对象继承
- 过滤广告(只能发布 [a-zA-z0-9及汉字,;?.]) ,排除其他特殊符号
- Batch批处理获取当前时间
- Tsx写一个通用的button组件
- 百度全景地图使用时提示flash版本过低 如何处理?
- 学习记录:《C++设计模式——李建忠主讲》3.“组件协作”模式
- NIO流的学习以及Buffer的相关操作
- ubuntu server 1604 配置网络信息
- 🙈羞,Spring Bean 初始化/销毁竟然有这么多姿势