Nginx網(wǎng)站服務(wù)——服務(wù)基礎(chǔ),訪問控制(實(shí)戰(zhàn)!)

關(guān)于Nginx

一款高性能,輕量級(jí)web服務(wù)軟件

穩(wěn)定性高
系統(tǒng)資源消耗低
對(duì)HTTP并發(fā)連接的處理能力高

成都創(chuàng)新互聯(lián)執(zhí)著的堅(jiān)持網(wǎng)站建設(shè),微信小程序定制開發(fā);我們不會(huì)轉(zhuǎn)行,已經(jīng)持續(xù)穩(wěn)定運(yùn)營十載。專業(yè)的技術(shù),豐富的成功經(jīng)驗(yàn)和創(chuàng)作思維,提供一站式互聯(lián)網(wǎng)解決方案,以客戶的口碑塑造品牌,攜手廣大客戶,共同發(fā)展進(jìn)步。

  • 單臺(tái)物理服務(wù)器可支持30000~50000個(gè)并發(fā)請(qǐng)求

環(huán)境

一臺(tái)Linux服務(wù)器(192.168.13.128)
一臺(tái)win10測(cè)試機(jī)

一,在Windows上將LAMP所需壓縮軟件包共享出來(此處如有問題請(qǐng)看之前的博客相關(guān)文章)

Nginx網(wǎng)站服務(wù)——服務(wù)基礎(chǔ),訪問控制(實(shí)戰(zhàn)?。?></p><h4>二,在Linux上使用遠(yuǎn)程共享獲取文件并掛載到mnt目錄下</h4><pre><code>[root@localhost ~]# smbclient -L //192.168.100.3/   ##遠(yuǎn)程共享訪問
Enter SAMBA\root's password: 

                Sharename       Type      Comment
                ---------       ----      -------
                LAMP-C7         Disk       
[root@localhost ~]# mount.cifs //192.168.100.3/LAMP-C7 /mnt  ##掛載到/mnt目錄下</code></pre>
<h4>三,編譯安裝Nginx</h4><h5>1,解壓源碼包到/opt下,并查看</h5>
<pre><code>[root@localhost ~]# cd /mnt    ##切換到掛載點(diǎn)目錄
[root@localhost mnt]# ls
apr-1.6.2.tar.gz                  Discuz_X2.5_SC_UTF8.zip  LAMP-php5.6.txt
apr-util-1.6.0.tar.gz             error.png                MySQL-5.6.26.tar.gz
awstats-7.6.tar.gz                httpd-2.4.29.tar.bz2     nginx-1.12.0.tar.gz
cronolog-1.6.2-14.el7.x86_64.rpm  kali.jpg                 php-5.6.11.tar.bz2
[root@localhost mnt]# tar zxvf nginx-1.12.0.tar.gz -C /opt   ##解壓Nginx源碼包到/opt下
[root@localhost mnt]# cd /opt/    ##切換到解壓的目錄下
[root@localhost opt]# ls
nginx-1.12.0  rh</code></pre>
<h5>2,安裝編譯需要的環(huán)境組件包</h5>
<pre><code>[root@localhost opt]# yum -y install \
gcc \                                       //c語言
gcc-c++ \                        //c++語言
pcre-devel \                     //pcre語言工具
zlib-devel                       //數(shù)據(jù)壓縮用的函式庫</code></pre>
<h5>3,創(chuàng)建程序用戶nginx并編譯Nginx</h5>
<pre><code>[root@localhost opt]# useradd -M -s /sbin/nologin nginx  ##創(chuàng)建程序用戶,安全不可登陸狀態(tài)
[root@localhost opt]# id nginx
uid=1001(nginx) gid=1001(nginx) 組=1001(nginx)
[root@localhost opt]# cd nginx-1.12.0/                 ##切換到nginx目錄下
[root@localhost nginx-1.12.0]# ./configure \         ##配置nginx
> --prefix=/usr/local/nginx \        ##安裝路徑
> --user=nginx \                         ##用戶名
> --group=nginx \                       ##用戶組
> --with-http_stub_status_module     ##狀態(tài)統(tǒng)計(jì)模塊</code></pre>
<h5>4,編譯和安裝</h5>
<pre><code>[root@localhost nginx-1.12.0]# make     ##編譯
...
[root@localhost nginx-1.12.0]# make install   ##安裝
...</code></pre>
<h5>5,優(yōu)化nginx啟動(dòng)腳本,以便于系統(tǒng)識(shí)別</h5>
<pre><code>[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/  ##創(chuàng)建軟連接讓系統(tǒng)識(shí)別nginx啟動(dòng)腳本
[root@localhost nginx]# nginx -t       ##檢查配置文件的語法問題
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@localhost nginx]# nginx      ##開啟ngnix
[root@localhost nginx]# netstat -ntap | grep 80     ##查看端口,nginx已經(jīng)開啟
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      39620/nginx: master 
[root@localhost nginx]# systemctl stop firewalld.service    ##關(guān)閉防火墻
[root@localhost nginx]# setenforce 0 </code></pre>
<h5>6,安裝elinks網(wǎng)頁測(cè)試工具,并進(jìn)行測(cè)試</h5>
<pre><code>[root@localhost nginx]# yum install elinks -y    ##安裝elinks軟件
[root@localhost nginx]# elinks http://localhost  ##測(cè)試nginx網(wǎng)頁</code></pre><p><img src=

7,服務(wù)開啟重載以及關(guān)閉
[root@localhost nginx]# killall -s QUIT nginx   ##停止 或者使用killall -3 nginx
[root@localhost nginx]# killall -s HUP nginx    ##重啟 或者使用killall -1 nginx
[root@localhost nginx]# nginx                         ##開啟
8,制作管理腳本,便于使用service管理使用
[root@localhost nginx]# cd /etc/init.d/   ##切換到啟動(dòng)配置文件目錄
[root@localhost init.d]# ls
functions  netconsole  network  README
[root@localhost init.d]# vim nginx         ##編輯啟動(dòng)腳本文件

#!/bin/bash
# chkconfig: - 99 20                                    ##注釋信息
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"           ##設(shè)置變量為nginx命令文件
PIDF="/usr/local/nginx/logs/nginx.pid"       ##設(shè)置變量PID文件 進(jìn)程號(hào)為5346
case "$1" in  
    start)
        $PROG                                              ##開啟服務(wù)
        ;;
    stop)
        kill -s QUIT $(cat $PIDF)                    ##關(guān)閉服務(wù)
        ;;
    restart)                                                  ##重啟服務(wù)
        $0 stop
        $0 start
        ;;
    reload)                                                  ##重載服務(wù)
        kill -s HUP $(cat $PIDF)
        ;;
    *)                                                           ##錯(cuò)誤輸入提示
                echo "Usage: $0 {start|stop|restart|reload}"
                exit 1
esac
exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx    ##給啟動(dòng)腳本執(zhí)行權(quán)限
[root@localhost init.d]# chkconfig --add nginx          ##添加到service管理器中
[root@localhost init.d]# service nginx stop                ##就可以使用service控制nginx
[root@localhost init.d]# service nginx start

Nginx的訪問狀態(tài)統(tǒng)計(jì)

  • 啟用HTTP_STUB_STATUS狀態(tài)統(tǒng)計(jì)模塊
  • nginx -V可以查看已安裝的Nginx是否包含統(tǒng)計(jì)模塊

一,修改nginx配置文件

[root@localhost ~]# cd /usr/local/nginx/conf     ##切換到配置文件目錄
[root@localhost conf]# vim nginx.conf              ##修改Nginx配置文件

server {
    listen       80;
    server_name  www.kgc.com;        ##指明一個(gè)域名

    charset utf-8;                                 ##中文字符集

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }
    location /status {                           ##添加狀態(tài)統(tǒng)計(jì)
    stub_status on;
    access_log off;
    }

二,安裝DNS服務(wù)器做域名解析

1,安裝bind服務(wù)
[root@localhost conf]# yum install bind -y   ##安裝DNS服務(wù)
2,配置主配置文件/etc/named.conf
 [root@localhost conf]# vim /etc/named.conf   ##主配置文件

options {
                listen-on port 53 { any; };      ##將本機(jī)監(jiān)聽為所有
                listen-on-v6 port 53 { ::1; };
                directory       "/var/named";
                dump-file       "/var/named/data/cache_dump.db";
                statistics-file "/var/named/data/named_stats.txt";
                memstatistics-file "/var/named/data/named_mem_stats.txt";
                recursing-file  "/var/named/data/named.recursing";
                secroots-file   "/var/named/data/named.secroots";
                allow-query     { any; };      ##允許所有
3,配置區(qū)域配置文件(etc/named.rfc1912.zones)
[root@localhost conf]# vim /etc/named.rfc1912.zones  ##配置區(qū)域配置文件
zone "localhost" IN {             ##復(fù)制模板到下面
                                type master;
                                file "named.localhost";
                                allow-update { none; };
};

zone "kgc.com" IN {              ##修改localhost為kgc.com
                                type master;
                                file "kgc.com.zone";      ##創(chuàng)建區(qū)域數(shù)據(jù)配置文件
                                allow-update { none; };
};
4,編輯區(qū)域數(shù)據(jù)配置文件( kgc.com.zone)
[root@localhost conf]# cd /var/named
[root@localhost named]# cp -p named.localhost kgc.com.zone   
##復(fù)制模板為kgc.com.zone
[root@localhost named]# vim kgc.com.zone  ##編輯區(qū)域數(shù)據(jù)配置文件

$TTL 1D
@       IN SOA  @ rname.invalid. (
                                                                        0       ; serial
                                                                        1D      ; refresh
                                                                        1H      ; retry
                                                                        1W      ; expire
                                                                        3H )    ; minimum
                                NS      @
                                A       127.0.0.1
www IN  A       192.168.13.128   ##刪除ipv6 添加域名解析地址為本機(jī)
5,關(guān)閉防火墻并開啟服務(wù)
[root@localhost named]# systemctl start named   ##開啟dns服務(wù)
[root@localhost named]# systemctl stop firewalld.service    ##關(guān)閉防火墻
[root@localhost named]# setenforce 0   ##關(guān)閉增強(qiáng)功能
6,利用win10測(cè)試機(jī)來測(cè)試

Nginx網(wǎng)站服務(wù)——服務(wù)基礎(chǔ),訪問控制(實(shí)戰(zhàn)?。?><br/><img src=

二,安裝httpd-tools工具包,設(shè)置密碼認(rèn)證文件

[root@localhost conf]# yum install httpd-tools -y    ##安裝工具包
[root@localhost conf]# htpasswd -c /usr/local/nginx/passwd.db test    ##設(shè)置密碼認(rèn)證文件
New password:          ##輸入密碼
Re-type new password:        ##確認(rèn)密碼
Adding password for user test
[root@localhost conf]# cat /usr/local/nginx/passwd.db      ##查看密碼認(rèn)證文件
test:$apr1$LqqHZeX3$24E7/HeacTVRzKA7nvSgY/
[root@localhost conf]# service nginx stop      ##關(guān)閉服務(wù)
[root@localhost conf]# service nginx start      ##開啟服務(wù)

三,使用win10測(cè)試機(jī)測(cè)試

Nginx網(wǎng)站服務(wù)——服務(wù)基礎(chǔ),訪問控制(實(shí)戰(zhàn)?。?><br/><img src=Nginx網(wǎng)站服務(wù)——服務(wù)基礎(chǔ),訪問控制(實(shí)戰(zhàn)?。?/a>
本文URL:http://bm7419.com/article42/psdchc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)站制作、做網(wǎng)站軟件開發(fā)、企業(yè)建站自適應(yīng)網(wǎng)站

廣告

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

外貿(mào)網(wǎng)站建設(shè)