nginx代理http实现动静分离
简单来说,就是使用正则表达式匹配过滤,然后交个不同的服务器。
准备一个nginx代理 http 分别处理动态和静态。也可以让nginx代理自己解析静态网页,不过nginx又代理又解析网站感觉压力也挺大的。
安装软件包
yum -y install httpd mariadb-server php* php-mysql php-gd
[root@localhost ~]# ll /etc/my.cnf
-rw-r–r--. 1 root root 570 11月 15 2016 /etc/my.cnf
[root@localhost ~]# systemctl enable --now mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
启动mariadb服务
[root@localhost ~]# systemctl enable --now mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# ss -tnl 查看端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 :
LISTEN 0 128 :22 :
LISTEN 0 128 :::22 :::
[root@localhost ~]# mysql_secure_installation 初始化数据库
全部回车
[root@localhost ~]# mysql -uroot -p123456789
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.52-MariaDB MariaDB Server
Copyright © 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> \q
[root@localhost ~]# echo "<?php phpinfo(); ?> " > /var/www/html/info.php
[root@localhost ~]# cat /var/www/html/info.php
<?php phpinfo(); ?>[root@localhost ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# sed -i ‘/^#S/s/#//’ /etc/httpd/conf/httpd.conf
[root@localhost ~]# grep ServerN /etc/httpd/conf/httpd.conf
ServerName gives the name and port that the server uses to identify itself.
ServerName www.example.com:80
打开浏览器查看php网页
192.168.168.10.110/info.php
crtl +f 搜索
[root@localhost ~]# yum -y localinstall ./*.rpm
[root@localhost ~]# rpm -q nginx
nginx-1.16.1-1.el7.ngx.x86_64
[root@localhost ~]# rpm -qc nginx
/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
[root@localhost ~]# vim /etc/nginx/nginx.conf