nginx学习笔记二

一.了解LMNP
1.L:linux M:mysql N:nginx P:php

二.配置LMNP
1.配置相应的环境
-准备nginx服务
-准备mariadb服务 yum -y install mariadb mariadb-server mariadb-devel
-准备php服务 yum -y install php php-mysql php-ftp

2.配置php服务
 vim /etc/php-fpm.d/www.conf  //配置进程数量

3.启动相应的服务
  一共需要启动三个服务(nginx,php-fpm,mariadb)
 systemctl start php-fpm
 systemctl start mariadb-service

三.配置动态网页
1.在nginx.conf配置文件中有相应的模版,将其注释解开
例如:
location ~ .php$ {
root ;
fastcgi_pass 127.0.0.1:9000; //设置在哪个主机的端口进行代码解析
fastcgi_index index.php;
include fastcgi.conf; //导入配置文件
}
2.重启nginx服务
nginx -s reload

四.了解日志文件
nginx的访问日志文件 /usr/local/nginx/logs/access.log
nginx的错误日志文件 /usr/local/nginx/logs/error.log
php的错误日志文件 /var/log/php-fpm/www-error.log

五.了解地址重写
1.访问a跳转到b,但url还是显示a
在nginx.conf配置文件中的server框中添加 rewrite
例如:
rewrite /a.html /b.html;

 2.访问a跳转b,url显示的是b
   例如:
 rewrite /a.html /b.html redirect;                 //需要在后面添加redirect

 3.访问www.a.com直接跳转到www.tmooc.cn
   例如:
 rewrite ^/ http://www.tmooc.cn/; 

 4.访问www.a.com下面的子目录跳转到www.tmooc.cn下面的子目录
   例如:
 rewrite /^(.*)$ http://www.tmooc.cn/$1;

 5.设置火狐浏览器和谷歌浏览器所提供的页面不同
   例如:
  if ($http_user_agent ~* firefox) { 
    rewrite ^(.*)$  /firefox/$1                   //将匹配到的内容放入firefox文件夹里
    }
   -$remote_addr:请求ip
   -$remote_user:用户名
   -[$time_local]:当地时间
   -$request:请求方式,访问资源目录
   -$status:状态码
   -$body_bytes_sent:流量大小
   -$http_referer:是否从其他网站跳转过来
   -$http_user_agent:上网代理

 6.地址重写格式
  rewrite 旧地址 新地址 [选项];
  last 不再读其他rewrite
  break 不再读其他语句,结束请求
  redirect 临时重定向
  permament 永久重定向

猜你喜欢

转载自blog.csdn.net/weixin_42917630/article/details/87976394
今日推荐