实现一套项目,所需要使用到的中间件环境
LNMP:用于不熟应用php项目
L linux系统
N nginx
M MySQL
P PHP
LNMT:用于部署应用Java项目
T:Tomcat
LAMP:
A:Apache
LAMT
php: ***.php java: ***.jsp .net: ***.asp python: ***.py
nginx和PHP交互的流程
1.nginx通过location匹配PHP后最的url 2.通过fasycgi接口解析讲请求发送给php 3.php-fpm派生php工作进程 4- 工作进程通过warrap组件派生工作线程请求php解析器 5- php解析器将Nginx给过来的文件进行语言解析,解析成html资源返回给Nginx 6- 如果代码中涉及到请求数据库的语句,则需要通过php-mysqlnd插件和数据库交互
php:超文本预处理器 php擅长编写前后端交互的过程 java:实现功能 前后端交互:php写交互 php的版本 php5 php 5.5 5.6 php7 7.1 7.2 7.3 7.4 php8 8.1 8.2 8.3
php的安装 yum安装 #配置php源 yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm #安装 yum install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache php72-php-pecl-redis 编译安装
rpm -qc php-fpm /etc/opt/remi/php72/php-fpm.conf -- php的主配置文件 /etc/opt/remi/php72/php-fpm.d/www.conf --php的项目配置文件 vim /etc/opt/remi/php72/php-fpm.d/www.conf 24 user = nginx 26 group = nginx 38 listen = 127.0.0.1:9000
systemctl start php72-php-fpm.service启动 systemctl restart php72-php-fpm.service 重启 systemctl status php72-php-fpm.service 查看
vim /usr/local/nginx/conf/conf.d/php.conf server { listen 80; server_name php.dms.com; root /html/php; index index.html index.php; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } #准备测试代码 mkdir /html/php echo '' >/html/php/index.php #重启nginx
yum install mariadb-server -y
systemctl start mariadb
mysqladmin password 123 #测试登录 mysql -uroot -p123
vim /html/php/test-db.php
vim /usr/local/nginx/conf/conf.d/wordpress.conf server { listen 80; server_name wordpress.dms.com; root /html/wordpress; index index.html index.php; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
#上传并解压 tar xvf WordPress-4.6.tar.gz、 #重命名目录保证代码路径和配置文件一致 #授权目录为nginx用户 chown -R nginx.nginx /html
mysql -uroot -p123 #创建wordpress库 create database wordpress; #查看wordpress库 show database;
将用户所访问的页面,进行跳转到其他的页面中
return 状态码 return url return 状态码'提示信息' 应用场景:隐藏不希望外界访问的页面,页面跳转功能 案例1:wordpress.dms.com/wp-admin 不允许访问 location ^~ /wp-admin { return 404; } 案例2:wordpress.dms.com/wp-admin 页面提示信息 location ^~ /wp-admin { return 404 "退退退"; default_type application/json; } 案例3:wordpress.dms.com/wp-admin 跳转到其他页面 location ^~ /wp-admin { return http://www.mps.gov.gov.cn/; }
rewrite 用户访问的uri路径 跳转的新的路径 跳转策略 跳转策略 last 每次跳转,重新发起请求的过程 break 每次跳转,先检查目录结构,如果有直接发起请求 permanent 永久重定向 301 redirect 临时重定向 302 应用场景:http跳转https #注意 http跳转https尽量使用301跳转 路径可能会发生变化的页面跳转使用302 ## 实验: location.dms.com/michael break location.dms.com/status location.dms.com/qiangge last location.dms.com/status location.dms.com/status 状态页面 ## nginx配置跳转 location /michael { rewrite /michael /status break; } location /qiangge { rewrite /qiangge /status last; } location /status { stub_status; } ## 案例2:实现return页面跳转功能,location.dms.com/admin --> location.dms.com location /admin { rewrite /admin http://location.dms.com break; }