日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

Nginx高级配置-官网logo之favicon.ico

發(fā)布時間:2023/12/15 综合教程 27 生活家
生活随笔 收集整理的這篇文章主要介紹了 Nginx高级配置-官网logo之favicon.ico 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

           Nginx高級配置-官網(wǎng)logo之favicon.ico

                                          作者:尹正杰

版權(quán)聲明:原創(chuàng)作品,謝絕轉(zhuǎn)載!否則將追究法律責(zé)任。

一.瀏覽器會默認幫咱們訪問官網(wǎng)的圖標

1>.瀏覽器訪問網(wǎng)站"http://node101.yinzhengjie.org.cn/"

2>.使用curl命令訪問

[root@node108.yinzhengjie.org.cn ~]# curl http://node101.yinzhengjie.org.cn/
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>字體的樣式</title>
        <style>
            .hello{
                color: red;
                font-size: 30px;
                font-family: "curlz mt","華文彩云","arial", "微軟雅黑";
            }
        </style>
    </head>
    <body>
        <p class="hello">2019尹正杰到此一游,在這里提前祝大家2020年新年快樂~</p>
    </body>
</html>

[root@node108.yinzhengjie.org.cn ~]# 

3>.可以看到后臺是有日志輸出的

[root@node101.yinzhengjie.org.cn ~]# > /yinzhengjie/softwares/nginx/logs/access_json.log             #在訪問之前,建議大家把日志清空,看的比較明顯哈~當然,我說的是測試環(huán)境。
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# tail  -10f /yinzhengjie/softwares/nginx/logs/access_json.log        #可以看到瀏覽器的訪問記錄被記錄了404錯誤信息,而使用命令行curl訪問的確是200正常訪問。
{"@timestamp":"2019-12-22T11:10:40+08:00","host":"172.30.1.101","clientip":"172.30.1.254","size":571,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":
"node101.yinzhengjie.org.cn","uri":"/favicon.ico","domain":"node101.yinzhengjie.org.cn","xff":"-","referer":"http://node101.yinzhengjie.org.cn/","tcp_xff":"",
"http_user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36","status":"404"}
{"@timestamp":"2019-12-22T11:47:35+08:00","host":"172.30.1.101","clientip":"172.30.1.101","size":362,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host": "node101.yinzhengjie.org.cn","uri":"/index.html","domain":"node101.yinzhengjie.org.cn","xff":"-","referer":"-","tcp_xff":"","http_user_agent":"curl/7.29.0","status":"200"}

3>.訪問虛擬主機"http://www.yinzhengjie.org.cn/",發(fā)現(xiàn)也出現(xiàn)類似的問題

4>.訪問虛擬主機"http://mobile.yinzhengjie.org.cn/",發(fā)現(xiàn)也出現(xiàn)類似的問題

5>.訪問"favicon.ico"依舊會出現(xiàn)問題

  favicon.ico文件是瀏覽器收藏網(wǎng)址時顯示的圖標,當客戶端使用瀏覽器問頁面時,瀏覽器會自己主動發(fā)起請求獲取頁面的favicon.ico文件,但是當瀏覽器請求的favicon.ico文件不存在時,服務(wù)器會記錄404日志,而且瀏覽器也會顯示404報錯。

二.關(guān)于favicon.ico的解決辦法

  既然知道favicon.ico是啥了,那就好辦了,找一個公司logo放上去就ok啦。

1>.從互聯(lián)網(wǎng)上下載一個logo咱們自己來用于模擬試驗

[root@node101.yinzhengjie.org.cn ~]# ll
total 0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# wget https://www.jd.com/favicon.ico
--2019-12-22 12:05:35--  https://www.jd.com/favicon.ico
Resolving www.jd.com (www.jd.com)... 220.194.105.131, 2408:8710:20:1140:8000::3
Connecting to www.jd.com (www.jd.com)|220.194.105.131|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25214 (25K) [image/x-icon]
Saving to: ‘favicon.ico’

100%[==================================================================================================================================>] 25,214      --.-K/s   in 0.002s  

2019-12-22 12:05:35 (10.0 MB/s) - ‘favicon.ico’ saved [25214/25214]

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 28
-rw-r--r-- 1 root root 25214 Mar 25  2016 favicon.ico
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

[root@node101.yinzhengjie.org.cn ~]# wget https://www.jd.com/favicon.ico                          #下載京東的logo

[root@node101.yinzhengjie.org.cn ~]# ll
total 28
-rw-r--r-- 1 root root 25214 Mar 25  2016 favicon.ico
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# wget https://img.alicdn.com/tps/i3/T1OjaVFl4dXXa.JOZB-114-114.png
--2019-12-22 12:07:01--  https://img.alicdn.com/tps/i3/T1OjaVFl4dXXa.JOZB-114-114.png
Resolving img.alicdn.com (img.alicdn.com)... 111.206.4.120, 111.206.4.115
Connecting to img.alicdn.com (img.alicdn.com)|111.206.4.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4540 (4.4K) [image/png]
Saving to: ‘T1OjaVFl4dXXa.JOZB-114-114.png’

100%[==================================================================================================================================>] 4,540       --.-K/s   in 0s      

2019-12-22 12:07:01 (1.07 GB/s) - ‘T1OjaVFl4dXXa.JOZB-114-114.png’ saved [4540/4540]

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 36
-rw-r--r-- 1 root root 25214 Mar 25  2016 favicon.ico
-rw-r--r-- 1 root root  4540 May 29  2017 T1OjaVFl4dXXa.JOZB-114-114.png
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

[root@node101.yinzhengjie.org.cn ~]# wget https://img.alicdn.com/tps/i3/T1OjaVFl4dXXa.JOZB-114-114.png        #下載淘寶的logo

2>.編輯子配置文件

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/https.conf               #我們把京東的logo放在虛擬主機為"www.yinzhengjie.org.cn"中
server {
    listen 80;
    listen 443 ssl;
    server_name www.yinzhengjie.org.cn;
   
    location / {
       root /yinzhengjie/data/web/nginx/static;
       index index.html;
    }

    location = /favicon.ico {
       root /yinzhengjie/data/web/nginx/images/jd;
    }
}
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/mobile.conf               #我們將淘寶下載的logo放在虛擬主機為"mobile.yinzhengjie.org.cn"中
server {
    listen 80;
    listen 443 ssl;
    server_name mobile.yinzhengjie.org.cn;

    ssl_certificate /yinzhengjie/softwares/nginx/certs/mobile.yinzhengjie.org.cn.crt;
    ssl_certificate_key /yinzhengjie/softwares/nginx/certs/mobile.yinzhengjie.org.cn.key;
    ssl_session_cache shared:sslcache:20m;
    ssl_session_timeout 10m;   

    location / {
       root /yinzhengjie/data/web/nginx/mobile;
       index index.html;
    }

    location /favicon.ico {
       root /yinzhengjie/data/web/nginx/images/taobao;
    }
}
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]#

3>.將下載的圖片放在指定路徑中

[root@node101.yinzhengjie.org.cn ~]# mkdir -pv /yinzhengjie/data/web/nginx/images/{jd,taobao{
mkdir: created directory ‘/yinzhengjie/data/web/nginx/images’
mkdir: created directory ‘/yinzhengjie/data/web/nginx/images/jd’
mkdir: created directory ‘/yinzhengjie/data/web/nginx/images/taobao’
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 36
-rw-r--r-- 1 root root 25214 Mar 25  2016 favicon.ico
-rw-r--r-- 1 root root  4540 May 29  2017 T1OjaVFl4dXXa.JOZB-114-114.png
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# mv favicon.ico /yinzhengjie/data/web/nginx/images/jd/
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# mv T1OjaVFl4dXXa.JOZB-114-114.png /yinzhengjie/data/web/nginx/images/taobao/favicon.ico
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll
total 0
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/data/web/nginx/images/ -R
/yinzhengjie/data/web/nginx/images/:
total 0
drwxr-xr-x 2 root root 25 Dec 22 12:46 jd
drwxr-xr-x 2 root root 25 Dec 22 12:47 taobao

/yinzhengjie/data/web/nginx/images/jd:
total 28
-rw-r--r-- 1 root root 25214 Mar 25  2016 favicon.ico

/yinzhengjie/data/web/nginx/images/taobao:
total 8
-rw-r--r-- 1 root root 4540 May 29  2017 favicon.ico
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

4>.重新加載nginx的配置文件

[root@node101.yinzhengjie.org.cn ~]# netstat -untalp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12283/nginx: master 
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      12283/nginx: master 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root     12283     1  0 12:30 ?        00:00:00 nginx: master process nginx
nginx    12284 12283  0 12:30 ?        00:00:00 nginx: worker process
nginx    12285 12283  0 12:30 ?        00:00:00 nginx: worker process
nginx    12286 12283  0 12:30 ?        00:00:00 nginx: worker process
nginx    12287 12283  0 12:30 ?        00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -s reload
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root     12283     1  0 12:30 ?        00:00:00 nginx: master process nginx
nginx    12406 12283  6 12:52 ?        00:00:00 nginx: worker process
nginx    12407 12283  5 12:52 ?        00:00:00 nginx: worker process
nginx    12408 12283  5 12:52 ?        00:00:00 nginx: worker process
nginx    12409 12283  5 12:52 ?        00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# netstat -untalp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12283/nginx: master 
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      12283/nginx: master 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

5>.訪問虛擬主機"http://www.yinzhengjie.org.cn/",發(fā)現(xiàn)logo可以正常顯示啦

6>.訪問虛擬主機"http://mobile.yinzhengjie.org.cn/",發(fā)現(xiàn)logo是可以正常顯示啦

總結(jié)

以上是生活随笔為你收集整理的Nginx高级配置-官网logo之favicon.ico的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。