web网站——nginx,LNMP部署03
nginx功能:
(1)web服务器:
默认网页目录为:/usr/share/nginx/html
(2)反向代理服务器:
nginx代替客户端访问后端服务器,后端服务器只知道是nginx的请求,并将结果返回给 nginx,nginx 在返回给客户端结果
找到nginx配置文件中 location,配置段如下,默认是空的参数
location / {
}
做反向代理,/ 后面加上虚拟路径名字,下面用 proxy_pass 模块和上游的服务器的url,例如:
location /node1 { proxy_pass http://192.168.210.131/; }
(3)负载均衡服务器:
nginx 负责转发客户端的请求,轮询到的后端服务器获得的是客户端的访问请求,服务器直接返回给客户端结果 先配置 location 中的反向代理,将客户端请求发送到一个集群(zn为集群名,可以随便起),然后用 upstream 模块声明集群,并写入后端的真实server的地址,例如:
include /etc/nginx/conf.d/*.conf; upstream zn { server 192.168.210.132 weight=2 max_fails=2 fail_timeout=2; server 192.168.210.131 weight=1 max_fails=2 fail_timeout=2; } server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; index index.php index.html; # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; location / { proxy_pass http://zn/; }
(4)动态页面配置
配置源:
[root@node1 yum.repos.d]# cat cdrom.repo epel.repo [cdrom] name=centos base enabled=1 gpgcheck=0 baseurl=http://mirrors.163.com/centos/7/os/x86_64/ [epel] name=Extra Packages for Enterprise Linux 7 - $basearch baseurl=http://mirrors.aliyun.com/epel/7/$basearch failovermethod=priority enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [epel-debuginfo] name=Extra Packages for Enterprise Linux 7 - $basearch - Debug baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=0 [epel-source] name=Extra Packages for Enterprise Linux 7 - $basearch - Source baseurl=http://mirrors.aliyun.com/epel/7/SRPMS failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=0
安装软件动态网站所需软件包:
yum install nginx php php-mysql mariadb-server mariadb php-gd -y
修改server段配置
server { listen 80 default_server; listen [::]:80 default_server; server_name _; #root /usr/share/nginx/html; root /date/wordpress; index index.php index.html; #添加index.php默认页 # Load configuration files for the default server block. #include /etc/nginx/default.d/*.conf; 注释掉 location ~ php$ { fastcgi_pass 127.0.0.1:9000; #php-fpm监听的地址 include fastcgi.conf; #加载fastcgi文件 } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }