欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Centos7部署Nginx網(wǎng)站服務(wù)

一、Nginx服務(wù)基礎(chǔ)

Nginx專為性能優(yōu)化而開發(fā),其最知名的優(yōu)點是它的穩(wěn)定性和低系統(tǒng)資源消耗,以及對HTTP并發(fā)連接的高處理能力(單臺物理服務(wù)器可支持30000~50000個并發(fā)請求)。正因為如此,大量提供社交網(wǎng)絡(luò)、新聞資訊、電子商務(wù)及虛擬主機等服務(wù)的企業(yè)紛紛選擇Nginx來提供Web服務(wù)。

專業(yè)從事企業(yè)網(wǎng)站建設(shè)和網(wǎng)站設(shè)計服務(wù),包括網(wǎng)站建設(shè)、國際域名空間、網(wǎng)頁空間、企業(yè)郵箱、微信公眾號開發(fā)、微信支付寶成都微信小程序、手機APP定制開發(fā)、軟件開發(fā)、等服務(wù)。公司始終通過不懈的努力和以更高的目標來要求自己,在不斷完善自身管理模式和提高技術(shù)研發(fā)能力的同時,大力倡導(dǎo)推行新經(jīng)濟品牌戰(zhàn)略,促進互聯(lián)網(wǎng)事業(yè)的發(fā)展。

1、Nginx服務(wù)的優(yōu)勢

Nginx是一個很牛的高性能Web和反向代理服務(wù)器,它具有有很多非常優(yōu)越的特性:

  • 高并發(fā)連接:官方測試能支撐5萬并發(fā)連接,在實際生產(chǎn)環(huán)境中跑到2,~3W并發(fā)連;
  • 內(nèi)存消耗少:在3W并發(fā)連接下,開啟的10個NGINX進程才消耗150M內(nèi)存(15M*10=150M);
  • 配置文件非常簡單:風(fēng)格跟程序一樣通俗易懂;
  • 成本低廉:Nginx作為開源軟件,可以免費使用,而購買F5 BIG-IP、NetScaler等硬件負載均衡交換機則需要十多萬至幾十萬人民幣;
  • 支持rewrite重寫規(guī)則:能夠根據(jù)域名、URL的不同,將HTTP請求分發(fā)到不同的后端服務(wù)器群組;
  • 內(nèi)置的健康檢查功能:如果Nginx Proxy后端的后臺web服務(wù)器宕機了,不會影響前端訪問;
  • 節(jié)省帶寬:支持GZIP壓縮,可以添加瀏覽器本地緩存的Header頭;
  • 穩(wěn)定性高:用于反向代理,宕機的概率微乎其微;

二、安裝部署Nginx

1、前提準備

Nginx最新的穩(wěn)定版本為1.12.0,其安裝文件可以從官方網(wǎng)站Nginx官方網(wǎng)站/下載。

1)Centos 7服務(wù)器一臺;
2)Windows客戶端一臺:
3)Centos 7操作系統(tǒng)鏡像;
4)Nginx鏡像;
安裝Nginx用到的所有鏡像及軟件包可以訪問網(wǎng)盤提?。篽ttps://pan.baidu.com/s/18iRCuiMEyGbEFSeBp17uVQ
提取碼:qszt

2、開始安裝部署Nginx服務(wù)器

1)掛載Linux光盤,拷貝nginx依賴程序到/usr/src/目錄

Centos 7部署Nginx網(wǎng)站服務(wù)

[root@centos02 ~]# mount /dev/cdrom /mnt/    <!--掛載光盤-->
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@centos02 ~]# cp /mnt/nginx-1.6.0.tar.gz /usr/src/ <!--拷貝Nginx包到/usr/src/目錄-->

2)切換LAMP光盤,將mnt目錄下所有數(shù)據(jù)拷貝到/usr/src/目錄

[root@centos02 ~]# umount /mnt/ &lt;!--卸載光盤--&gt;
Centos 7部署Nginx網(wǎng)站服務(wù)

[root@centos02 ~]# mount /dev/cdrom /mnt/   <!--掛載光盤-->
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@centos02 ~]# cp /mnt/* /usr/src/ <!--將光盤目錄下所有數(shù)據(jù)拷貝到/usr/src/目錄-->

3)切換到操作系統(tǒng)光盤,安裝nginx依賴程序

[root@centos02 ~]# umount /mnt/ &lt;!--卸載光盤--&gt;
Centos 7部署Nginx網(wǎng)站服務(wù)

[root@centos02 ~]# mount /dev/cdrom /mnt/   <!--掛載光盤-->
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@centos02 ~]# rm -rf /etc/yum.repos.d/CentOS-* <!--清除系統(tǒng)自帶yum源-->
[root@centos02 ~]# yum -y install pcre-devel zlib-devel <!--安裝Nginx的依賴程序-->
[root@centos02 ~]# useradd -M -s /sbin/nologin nginx <!--創(chuàng)建管理Nginx的用戶-->
[root@centos02 ~]# tar zxvf /usr/src/nginx-1.6.0.tar.gz -C /usr/src/ 
<!--解壓縮Nginx軟件包-->
[root@centos02 ~]# cd /usr/src/nginx-1.6.0/ 
[root@centos02 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx
--user=nginx --group=nginx --with-http_stub_status_module
<!--配置Nginx-->
[root@centos02 nginx-1.6.0]# make && make install  <!--編譯安裝Nginx-->
[root@centos02 ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ <!--優(yōu)化Nginx執(zhí)行命令-->

3、Nginx服務(wù)的基本管理

[root@centos02 ~]# nginx    <!--啟動Nginx服務(wù)-->
[root@centos02 ~]# netstat -anptu | grep nginx 
                     <!--監(jiān)聽Nginx服務(wù)是否啟動成功-->
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4663/nginx: master  
[root@centos02 ~]# killall -s QUIT nginx   <!--關(guān)閉Nginx服務(wù)-->
[root@centos02 ~]# killall -3 nginx       <!--關(guān)閉Nginx服務(wù)-->
[root@centos02 ~]# killall -1 nginx     <!--重新啟動Nginx-->
[root@centos02 ~]# killall -s HUP nginx   <!--重新啟動Nginx-->
[root@centos02 ~]# vim /etc/init.d/nginx <!--編寫Nginx服務(wù)管理腳本-->
#!/bin/bash
#chkconfig: 35 90 30
#description:nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill 0s HUP $(cat $PIDF)
;;
*)
echo "Usage:$0 (start|stop|restart|reload)"
exit 1
esac
exit 0
[root@centos02 ~]# chmod +x /etc/init.d/nginx <!--添加腳本執(zhí)行權(quán)限-->
[root@centos02 ~]# chkconfig --add nginx <!--添加為系統(tǒng)服務(wù)-->
[root@centos02 ~]# chkconfig --level 35 nginx on <!--設(shè)置開機自動啟動-->
[root@centos02 ~]# /etc/init.d/nginx stop<!--腳本停止Nginx服務(wù)-->
[root@centos02 ~]# /etc/init.d/nginx start<!--腳本啟動Nginx服務(wù)-->
[root@centos02 ~]# /etc/init.d/nginx restart<!--腳本重啟Nginx服務(wù)-->

客戶端配置和Nginx服務(wù)器同一塊網(wǎng)卡同網(wǎng)段,設(shè)置網(wǎng)關(guān)即可訪問Nginx網(wǎng)站服務(wù)器
Centos 7部署Nginx網(wǎng)站服務(wù)

4、Nginx常見的配置文件

[root@centos02 ~]# ls -ld /usr/local/nginx/conf/nginx.conf
-rw-r--r-- 1 root root 2656 11月 28 17:22
/usr/local/nginx/conf/nginx.conf       <!--Nginx的主配置文件-->
[root@centos02 ~]# ls -ld /usr/local/nginx/sbin/
drwxr-xr-x 2 root root 19 11月 28 17:22
/usr/local/nginx/sbin/      <!--管理Nginx服務(wù)程序文件-->
[root@centos02 ~]# ls -ld /usr/local/nginx/html/
drwxr-xr-x 2 root root 40 11月 28 17:22
/usr/local/nginx/html/      <!--Nginx的網(wǎng)站根目錄-->
[root@centos02 ~]# ls -ld /usr/local/nginx/logs/
drwxr-xr-x 2 root root 58 11月 28 17:47 
/usr/local/nginx/logs/   <!--Nginx的網(wǎng)站日志記錄-->

5、修改Nginx主配置文件

[root@centos02 ~]# cp /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.bak   <!--備份主配置文件-->
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf 
                            <!--編輯主配置文件-->
  3 user  nginx;       <!--運行用戶-->
  4 worker_processes  1;     <!--工作進程數(shù)量-->
  6 error_log  logs/error.log;   <!--錯誤日志文件的位置-->
12 pid        logs/nginx.pid;     <!--PID文件的位置-->
16     use epoll;        <!--使用epoll模型-->
17     worker_connections  1024; <!--每進程處理1024個連接-->
29     #access_log  logs/access.log  main; <!--訪問日志的位置-->
31     sendfile        on;           <!--開啟高效傳輸文件模式-->
35     keepalive_timeout  65;       <!--連接保持超時-->
39     server { <!--server的開始,一個server表示一個虛擬主機-->
40         listen       80;     <!--Web服務(wù)的監(jiān)聽配置-->
41         server_name  localhost; <!--網(wǎng)站名稱(FQDN)-->
44         charset utf-8;    <!--網(wǎng)頁的默認字符集-->
48         location / {     <!--根目錄配置-->
49             root   html; <!--網(wǎng)站根目錄的位置,相對于安裝目錄-->
50             index  index.html index.html;<!--默認首頁(索引頁)-->
51         }
84     }            <!--server結(jié)束-->
  • listen:限定端口的同時允許限定IP地址,采用“IP地址:端口號”形式,root語句用來設(shè)置特定訪問位置的網(wǎng)頁文檔路徑,默認為Nginx安裝目錄下的html/目錄,根據(jù)需要可改為/var/www/html等其他路徑,但更改后需保證nginx用戶對其具有讀取權(quán)限。

  • worker_processes :表示工作進程的數(shù)量,若服務(wù)器由多塊CPU或者使用多核處理器,可以參考CPU核心總數(shù)來指定工作進程數(shù)。具體含義在worker_connections配置項中體現(xiàn)出來。

  • worker_connections:這個配置項指定的是每個進程處理的連接,一般在10000以下(默認為1024),與上面工作進程數(shù)量的配置項關(guān)聯(lián),例如:若工作進程數(shù)為8,每個進程處理4096個連接,則允許Nginx正常提供服務(wù)的連接數(shù)已經(jīng)超過了3萬個(4096*8=32768)。當然,具體還要看服務(wù)器硬件、網(wǎng)絡(luò)帶寬等物理條件的性能表現(xiàn)。

6、配置Nginx的訪問狀態(tài)統(tǒng)計

[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf 
 <!--修改nginx配置文件,指定訪問位置并打開stub_status配置-->
 52         location /status {
 53                 stub_status     on;
 54                 access_log off;
 55         }
[root@centos02 ~]# /etc/init.d/nginx restart<!--重啟Nginx服務(wù)--> 

客戶端訪問狀態(tài)統(tǒng)計頁:
Centos 7部署Nginx網(wǎng)站服務(wù)

  • Active connections:表示當前的活動連接數(shù);

  • server accepts handled requests:表示已經(jīng)處理的連接信息,三個數(shù)字依次表示已處理的連接數(shù)、成功的TCP握手次數(shù)、已經(jīng)處理的請求數(shù)。

三、配置虛擬主機

1、安裝DNS服務(wù)器

[root@centos02 ~]# yum -y install bind bind-chroot bind-utils 
                              <!--安裝DNS-->
[root@centos02 ~]# echo "" > /etc/named.conf 
           <!--清空主配置文件-->
[root@centos02 ~]# vim /etc/named.conf <!--修改主配置文件-->
options {
        listen-on port 53 { 192.168.100.20; };
        directory "/var/named";
}
zone    "benet.com"     IN      {
        type    master;
        file    "benet.com.zone";
}
zone    "accp.com"      IN      {
        type    master;
        file    "accp.com.zone";
}
[root@centos02 ~]# named-checkconf -z /etc/named.conf
              <!--檢查主配置文件是否配置錯誤-->
[root@centos02 ~]# vim /var/named/benet.com.zone  
               <!--配置benet.com的正向解析區(qū)域-->
$TTL    86400
@       SOA     benet.com.      root.benet.com(
        2019112801
        1H
        15M
        1W
        1D
)
@       NS      centos02.benet.com.
centos02 A      192.168.100.20
www      A      192.168.100.20
[root@centos02 ~]# chmod +x /var/named/benet.com.zone  
                    <!--正向解析區(qū)域配置文件添加執(zhí)行權(quán)限-->
[root@centos02 ~]# chown named:named
/var/named/benet.com.zone <!--修改屬主屬組-->
[root@centos02 ~]# named-checkzone benet.com
/var/named/benet.com.zone   
         <!--檢查benet.com正向解析區(qū)域配置文件是否錯誤-->
zone benet.com/IN: loaded serial 2019112801
OK
[root@centos02 ~]# cp /var/named/benet.com.zone
/var/named/accp.com.zone  
   <!--復(fù)制benet.com正向解析區(qū)域到accp.com正向解析區(qū)域-->
[root@centos02 ~]# vim /var/named/accp.com.zone  
                    <!--修改accp.com正向解析區(qū)域配置文件-->
$TTL    86400
@       SOA     accp.com.       root.accp.com(
        2019112801
        1H
        15M
        1W
        1D
)
@       NS      centos02.accp.com.
centos02 A      192.168.100.20
www      A      192.168.100.20
[root@centos02 ~]# named-checkzone accp.com
/var/named/accp.com.zone  
           <!--檢查accp.com正向解析區(qū)域配置文件是否錯誤-->
[root@centos02 ~]# vim /etc/sysconfig/network-scripts/
ifcfg-ens32  <!--編輯網(wǎng)卡添加主DNS-->
DNS1=192.168.100.20   <!--添加主DNS-->
[root@centos02 ~]# systemctl restart network<!--重啟網(wǎng)卡服務(wù)-->
[root@centos02 ~]# systemctl start named <!--啟動DNS服務(wù)器-->
[root@centos02 ~]# systemctl enable named<!--設(shè)置開機自動啟動-->
[root@centos02 ~]# nslookup www.benet.com  
                 <!--解析域名測試是否正常-->
Server:     192.168.100.20
Address:    192.168.100.20#53

Name:   www.benet.com
Address: 192.168.100.20

[root@centos02 ~]# nslookup www.accp.com
                  <!--解析域名測試是否正常-->
Server:     192.168.100.20
Address:    192.168.100.20#53

Name:   www.accp.com
Address: 192.168.100.20

2、配置基于域名的虛擬主機

Nginx的配置文件使用“http { }”界定標記用于設(shè)定HTTP服務(wù)器,包括訪問日志、http端口、網(wǎng)頁目錄、默認字符集、連接保持,以及虛擬web主機、php解析等網(wǎng)站全局設(shè)置,其中大部分包含在子界定標記 “ server { }”內(nèi)?!?server { }”代表一個具體的網(wǎng)站設(shè)置。

            <!--創(chuàng)建虛擬主機網(wǎng)站根目錄--> 
[root@centos02 ~]# mkdir -p /var/www/benetcom  
[root@centos02 ~]# mkdir -p /var/www/accpcom  
              <!--創(chuàng)建虛擬主機的網(wǎng)站主頁--> 
[root@centos02 ~]# echo "www.benet.com" > 
/var/www/benetcom/index.html
[root@centos02 ~]# echo "www.accp.com" > 
/var/www/accpcom/index.html
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf  
                     <!--修改Nginx主配置文件支持虛擬主機-->
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
        server  {           <!--server開始-->
                listen www.benet.com:80;  <!--監(jiān)聽的域名及端口-->
                server_name www.benet.com;     <!--網(wǎng)站名稱-->
                charset utf-8;          <!--默認字符集-->
                access_log      logs/www.benet.com.access.log; 
                                                    <!--訪問日志位置-->
                error_log       logs/www.benet.com.error.log;
                                                       <!--錯誤日志位置-->
                location / {       <!--根目錄配置-->
                                root /var/www/benetcom/; <!--網(wǎng)站根目錄-->
                                index index.html;       <!--默認首頁-->
                        }
                }       <!--server結(jié)尾-->

<!--以下配置請參考以上注釋-->
        server  {
                listen www.accp.com:80;
                server_name www.accp.com;
                charset utf-8;
                access_log      logs/www.accp.com.access.log;
                error_log       logs/www.accp.com.error.log;
                location / {
                                root /var/www/accpcom/;
                                index index.html;
                        }
                }
[root@centos02 ~]# nginx -t   <!--檢查Nginx是否配置錯誤-->
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@centos02 ~]# systemctl restart named<!--重新啟動DNS服務(wù)-->
[root@centos02 ~]# /etc/init.d/nginx restart<!--重新啟動Nginx服務(wù)-->

客戶端添加DNS地址,訪問域名測試是否成功
Centos 7部署Nginx網(wǎng)站服務(wù)

Centos 7部署Nginx網(wǎng)站服務(wù)

—————— 本文至此結(jié)束,感謝閱讀 ——————

網(wǎng)站欄目:Centos7部署Nginx網(wǎng)站服務(wù)
網(wǎng)頁地址:http://chinadenli.net/article4/poocie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、靜態(tài)網(wǎng)站、做網(wǎng)站、云服務(wù)器網(wǎng)站改版、品牌網(wǎng)站設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營