部署LNMP 、 Nginx+FastCGI 、 Nginx高级技术
- 
安装nginx
 - 
安装mariadb 3306 客户端 服务端 开发环境
 
- 
[root@localhost nginx]# yum -y install mariadb [root@localhost nginx]# yum -y install mariadb-server [root@localhost nginx]# yum -y install mariadb-devel 
 - 
安装php
 - 
解释器 php与数据库交流 php与nginx交流 php-fpm 9000
yum -y install php php-mysql yum -y install php-fpm 
 - 
启动
 
- 
启动nginx 启动数据库 [root@localhost nginx]# systemctl restart mariadb [root@localhost nginx]# systemctl status mariadb [root@localhost nginx]# systemctl enable mariadb [root@localhost nginx]# netstat -ntulp | grep :3306 启动php-fpm [root@localhost nginx]# systemctl restart php-fpm [root@localhost nginx]# systemctl status php-fpm [root@localhost nginx]# systemctl enable php-fpm [root@localhost nginx]# netstat -ntulp | grep :9000 
 - 
配置nginx
 
- 
~ 使用正则表达式 fastcgi 公共网关接口 可以让网站服务与脚本解释器沟通的一个标准
 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; include fastcgi.conf; } 
 
修改php-fpm的配置
一个 php-fpm 子进程 大概消耗20M内存 15~ 25M
[root@localhost conf]# vim /etc/php-fpm.d/www.conf ## 最大能开多少个php-fpm pm.max_children = 50 ## 默认一开始开几个 pm.start_servers = 5 
地址重写 伪静态
rewrite ^/a.html$ /b.html; 直接就支持正则
server { listen 80; server_name localhost; rewrite ^/a.html$ /b.html; 
redirect 地址栏也跳到b
	
	    server {
	        listen       80;
	        server_name  localhost;
	rewrite ^/a.html$ /b.html redirect;
跳到别的网站
    server {
        listen       80;
        server_name  localhost;
rewrite ^/ http://www.tmooc.cn;
不同域名相同页面的跳转
	    server {
	        listen       80;
	        server_name  localhost;
	rewrite ^/(.*) http://www.tmooc.cn/$1;
不同客户端显示不同的网站 $http_user_agent ~* firefox
~ 使用正则
- 
忽略大小写
 
	
	    server {
	        listen       80;
	        server_name  localhost;
	
	        #charset koi8-r;
	charset utf-8;
	
	        #access_log  logs/host.access.log  main;
	
	        location / {
	            root   html;
	            index  index.html index.htm;
	        }
	if ($http_user_agent ~* firefox) {
	rewrite ^(.*)$ /firefox/$1;
	}
- 在location之外 last 匹配就忽略后面的重写规则 break 可以实现与last一样的效果 - 在location之内 last 只能停止当前区域内的重写规则 break 全局停止匹配重写规则,范围大 redirect 地址栏会变,临时重定向 permanent 永久重定向
状态码
200 一切正常 302 临时重定向 搜索引擎不感兴趣 304 缓存 301 永久重定向 搜索引擎会记录
					点赞
				
    








