operation day2

本文详细介绍了如何部署LNMP环境(Linux+Nginx+MariaDB+PHP/Python),包括FastCGI的配置以支持PHP动态页面处理,以及地址重写规则的设置,以便于URL管理与安全性提升。
摘要由CSDN通过智能技术生成

今日内容 部署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的地址重写的传递作用
​

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值