今日内容 部署LNMP、FastCGI、地址重写
一、部署LNPM环境
1.LNMP=linux+nginx+mariadb+php/python
2.nginx默认不能解析php动态页面的内容
3.环境部署
yum -y install gcc make openssl-devel pcre-devel cd /root/lnmp_soft/nginx-1.22.1 ./configure --with-http_ssl_module make && make install yum -y install mariadb mariadb-server mariadb-devel yum -y install php php-fpm php-mysqlnd systemctl start mariadb systemctl enable mariadb systemctl start php-fpm systemctl enable php-fpm cd /usr/local/nginx sbin/nginx ss -nutpl | grep mysql ss -nutpl | grep :80 ss -nutpl | grep php-fpm cp ~/lnmp_soft/php_scripts/tests.php /usr/local/nginx/html 测试无法访问192.168.88.88/test.php,只下载
二、构建LNMP平台--FastCGI
1.fastcgi:支持解析php动态页面,其实现工具是php-fpm
2.分类:网络(适用于nginx与php-fpm不在同一个服务器上)、接口(适用于nginx与php-fpm在同一个服务器上)
3.网络方式
1)配置php-fpm vim /etc/php-fpm.d/www.conf [www] listen=127.0.0.1:9000 listen.acl_users=nginx,apache,nobody 2)配置nginx vim conf/nginx.conf # 打开注释 location ~* \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } 3)启服务 systemctl restart php-fpm sbin/nginx -s reload 4)访问测试--成功
4.接口方式
1)配置php-fpm vim /etc/php-fpm.d/www.conf [www] listen=/run/php-fpm/www.sock listen.acl_users=nginx,apache,nobody 2)配置nginx vim conf/nginx.conf # 打开注释 location ~* \.php$ { root html; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; include fastcgi.conf; } 3)启服务 systemctl restart php-fpm sbin/nginx -s reload 4)访问测试--成功
5.访问数据库的php页面
cp ~/root/lnmp_soft/php_scripts/mysql.php html/ mysql create user dc@localhost identified by "123"; quit mysql -udc -p123 quit 访问成功
三、地址重写
1.定义:获取一个来访的url,然后改写服务器可以处理成为另一个url
2.作用:方便记忆、方便被爬虫、更加安全
3.配置
1) server{ listen 80; server_name localhost; rewrite /a.html /b.html; # 在html下创建a.html b.html location / { root html; index index.html index.htm; } } 2) server{ listen 80; server_name localhost; rewrite ^/a.html$ /b.html; .... } 3) server{ listen 80; server_name localhost; rewrite ^/a.html$ /b.html redirect; .... } 4) server{ listen 80; server_name localhost; rewrite ^/a.html$ /b.html permanent; .... } 5) server{ listen 80; server_name localhost; rewrite / http://www.tmooc.cn; .... } 6) server{ listen 80; server_name localhost; rewrite /(.*) http://www.tmooc.cn/$1; # 复制与粘贴 .... } 7) server{ ... if ($http_user_agent ~* firefox){ rewrite (.*) /firefox/$1; } } makir html/firefox echo firefox > html/firefox/a.html echo firefox > html/a.html 8)last 用于阻隔同一个location中的地址重新传递 9)break用于组个整个所有location的地址重写的传递作用