2019-06-04日 HTTP補(bǔ)充及ngnix基礎(chǔ)

HTTP補(bǔ)充

URL 統(tǒng)一資源定位符 網(wǎng)址
URI 統(tǒng)一資源標(biāo)識(shí)符 范圍更廣

|------------URL------------------|
www.oldboyedu.com/images/lidao.jpg
|-------URI------|

SEM 百度競(jìng)價(jià)
SEO 搜索引擎優(yōu)化

  • 偽裝成靜態(tài)頁(yè)面:偽靜態(tài)

Nginx ( engine x )基礎(chǔ)

功能

  • 1.web服務(wù)器 (http請(qǐng)求 http響應(yīng))
  • 2.nginx負(fù)載均衡
  • 3.nginx緩存

nginx apache
tengine (淘寶基于nginx2次開(kāi)發(fā)) web服務(wù)器

nginx apache主要區(qū)別:

nginx 異步模型 epoll
apache 同步模型 select

nginx安裝方式:

  • 1.安裝Nginx軟件所需依賴包
yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
  • 2.配置nginx官方 yum源
[root@web ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
  • 3.安裝nginx
[root@web01 ~]# yum repolist 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
nginx                                                                                             | 2.9 kB  00:00:00     
nginx/x86_64/primary_db                                                                           |  46 kB  00:00:01     
repo id                                   repo name                                                                status
base/7/x86_64                             CentOS-7 - Base - mirrors.aliyun.com                                     10,019
epel/x86_64                               Extra Packages for Enterprise Linux 7 - x86_64                           13,221
extras/7/x86_64                           CentOS-7 - Extras - mirrors.aliyun.com                                      409
nginx/x86_64                              nginx repo                                                                  152
updates/7/x86_64                          CentOS-7 - Updates - mirrors.aliyun.com                                   1,982
repolist: 25,783
[root@web01 ~]# yum list nginx 
[root@web01 ~]# yum list nginx 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
nginx.x86_64                                           1:1.16.0-1.el7.ngx                                           ngin    
  • 4.檢查及有關(guān)文件簡(jiǎn)介
[root@web01 ~]# rpm -qa nginx 
nginx-1.16.0-1.el7.ngx.x86_64
[root@web01 ~]# rpm -ql nginx 
/etc/logrotate.d/nginx                     #nginx日志切割的配置文件
    /etc/nginx
        /etc/nginx/nginx.conf              #nginx主配置文件 
        /etc/nginx/conf.d
        /etc/nginx/conf.d/default.conf     #nginx.conf一樣 
        /etc/nginx/mime.types              #媒體類(lèi)型 (http協(xié)議中的文件類(lèi)型)
        /etc/nginx/fastcgi_params
        /etc/nginx/koi-utf
        /etc/nginx/koi-win
        /etc/nginx/modules
        /etc/nginx/scgi_params
        /etc/nginx/uwsgi_params
        /etc/nginx/win-utf
/etc/sysconfig/nginx                       #systemctl 管理 nginx的使用的文件

/usr/lib/systemd/system/nginx.service      #systemctl 管理nginx(開(kāi) 關(guān) 重啟 reload) 配置文件       

/usr/sbin/nginx                            #nginx命令
/usr/sbin/nginx-debug

/usr/share/nginx/html                      #站點(diǎn)目錄 網(wǎng)站的根目錄 www.oldboyedu.com/oldboy.jpg 
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx                             #nginx日志 access.log 訪問(wèn)日志

[root@web01 ~]# nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

  • 5.啟動(dòng)
[root@web01 ~]# systemctl start nginx 
[root@web01 ~]# ps -ef |grep nginx 
root       8398      1  0 10:51 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx      8399   8398  0 10:51 ?        00:00:00 nginx: worker process
root       8425   7482  0 10:51 pts/0    00:00:00 grep --color=auto nginx


systemctl start  nginx     ===== nginx 
systemctl reload nginx     ===== nginx -s reload 
systemctl stop   nginx     ===== nginx -s stop 
  • 6.nginx -t #檢查語(yǔ)法
[root@web01 ~]# nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 ~]# systemctl start nginx 
[root@web01 ~]# ps -ef |grep nginx 
root       8512      1  0 11:15 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx      8513   8512  0 11:15 ?        00:00:00 nginx: worker process
root       8516   7482  0 11:15 pts/0    00:00:00 grep --color=auto nginx

[root@web01 ~]# ss -lntup |grep nginx 
tcp    LISTEN     0      128       *:80                    *:*                   users:(("nginx",pid=8399,fd=6),("nginx",pid=8398,fd=6))

[root@web01 ~]# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

  • 7.配置文件
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    server   {
        listen       80;
        server_name  localhost;
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    }
}
nginx配置文件詳解.png

測(cè)試

www.oldboy.com
顯示
www.oldboy.com

[root@web01 /etc/nginx]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.5      lb01
172.16.1.6      lb02
172.16.1.7      web01 www.oldboy.com      #配置www.oldboy.com 的hosts解析
172.16.1.8      web02
172.16.1.31     nfs01
172.16.1.41     backup
172.16.1.51     db01 db01.etiantian.org
172.16.1.61     m01
  • 檢查解析是否成功
[root@web01 /etc/nginx]# ping www.oldboy.com 
PING web01 (172.16.1.7) 56(84) bytes of data.
64 bytes from web01 (172.16.1.7): icmp_seq=1 ttl=64 time=0.036 ms
64 bytes from web01 (172.16.1.7): icmp_seq=2 ttl=64 time=0.055 ms
^C
--- web01 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.036/0.045/0.055/0.011 ms
[root@web01 /etc/nginx]# echo www.oldboy.com  >/usr/share/nginx/html/index.html 
[root@web01 /etc/nginx]# 
[root@web01 /etc/nginx]# curl  www.oldboy.com
www.oldboy.com
[root@web01 /etc/nginx]# curl -v  www.oldboy.com
* About to connect() to www.oldboy.com port 80 (#0)
*   Trying 172.16.1.7...
* Connected to www.oldboy.com (172.16.1.7) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: www.oldboy.com
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/1.16.0
< Date: Tue, 04 Jun 2019 04:09:23 GMT
< Content-Type: text/html
< Content-Length: 15
< Last-Modified: Tue, 04 Jun 2019 04:09:09 GMT
< Connection: keep-alive
< ETag: "5cf5eee5-f"
< Accept-Ranges: bytes
< 

www.oldboy.com

  • Connection #0 to host www.oldboy.com left intact
    到此為止Linux命令行測(cè)試ok
    測(cè)試windows瀏覽器訪問(wèn)
  • windows hosts解析(寫(xiě)法與linux一致) C:\Windows\System32\drivers\etc\hosts
    瀏覽器訪問(wèn)即可

tcp三次握手
http

nginx 多個(gè)網(wǎng)站
nginx 訪問(wèn)日志格式
nginx location

curl
-v
-I
-L

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末枝恋,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌帽氓,老刑警劉巖母赵,帶你破解...
    沈念sama閱讀 218,941評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件特恬,死亡現(xiàn)場(chǎng)離奇詭異舆逃,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)背捌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,397評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)毙籽,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人毡庆,你說(shuō)我怎么就攤上這事坑赡。” “怎么了么抗?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,345評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵毅否,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我蝇刀,道長(zhǎng)螟加,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,851評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮仰迁,結(jié)果婚禮上甸昏,老公的妹妹穿的比我還像新娘。我一直安慰自己徐许,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,868評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布卒蘸。 她就那樣靜靜地躺著雌隅,像睡著了一般。 火紅的嫁衣襯著肌膚如雪缸沃。 梳的紋絲不亂的頭發(fā)上恰起,一...
    開(kāi)封第一講書(shū)人閱讀 51,688評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音趾牧,去河邊找鬼检盼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛翘单,可吹牛的內(nèi)容都是我干的吨枉。 我是一名探鬼主播,決...
    沈念sama閱讀 40,414評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼哄芜,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼貌亭!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起认臊,我...
    開(kāi)封第一講書(shū)人閱讀 39,319評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤圃庭,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后失晴,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體剧腻,經(jīng)...
    沈念sama閱讀 45,775評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評(píng)論 3 336
  • 正文 我和宋清朗相戀三年涂屁,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了书在。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,096評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡胯陋,死狀恐怖蕊温,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情遏乔,我是刑警寧澤义矛,帶...
    沈念sama閱讀 35,789評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站盟萨,受9級(jí)特大地震影響凉翻,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜捻激,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,437評(píng)論 3 331
  • 文/蒙蒙 一制轰、第九天 我趴在偏房一處隱蔽的房頂上張望前计。 院中可真熱鬧,春花似錦垃杖、人聲如沸男杈。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,993評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)伶棒。三九已至,卻和暖如春彩库,著一層夾襖步出監(jiān)牢的瞬間肤无,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,107評(píng)論 1 271
  • 我被黑心中介騙來(lái)泰國(guó)打工骇钦, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留宛渐,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,308評(píng)論 3 372
  • 正文 我出身青樓眯搭,卻偏偏與公主長(zhǎng)得像窥翩,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子坦仍,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,037評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容