web網站——nginx,LNMP部署03

nginx功能:php

(1)web服務器:html

默認網頁目錄爲:/usr/share/nginx/htmlnode

 

(2)反向代理服務器:mysql

       nginx代替客戶端訪問後端服務器,後端服務器只知道是nginx的請求,並將結果返回給 nginx,nginx 在返回給客戶端結果nginx

找到nginx配置文件中 location,配置段以下,默認是空的參數web

location / { }

作反向代理,/ 後面加上虛擬路徑名字,下面用 proxy_pass 模塊和上游的服務器的url,例如:sql

location /node1 { proxy_pass http://192.168.210.131/;
        }

 

(3)負載均衡服務器:後端

        nginx 負責轉發客戶端的請求,輪詢到的後端服務器得到的是客戶端的訪問請求,服務器直接返回給客戶端結果       先配置 location 中的反向代理,將客戶端請求發送到一個集羣(zn爲集羣名,能夠隨便起),而後用 upstream 模塊聲明集羣,並寫入後端的真實server的地址,例如:centos

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 { } }
相關文章
相關標籤/搜索