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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

不能忽略的Nginx做web服务器的favicon.ico图像找不到问题

發布時間:2023/11/27 生活经验 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 不能忽略的Nginx做web服务器的favicon.ico图像找不到问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們在使用Nginx搭建HTTP的web server的過程中,一般都很順利,默認的網站根目錄一般是/usr/local/nginx/html,我們也可以正常訪問到Nginx的歡迎信息,比如使用下面的網址:

http://localhost/

但是發現運行一段時間后,Nginx的error日志中會定期抱怨說,沒有找到favicon.ico文件?

發生這種錯誤的原因一般是Nginx在根目錄上找不到這個文件。我們可以在網上下載一個ico文件放在根目錄下面就可以了。但是現在的業務場景有些區別:

我使用Nginx作為前臺服務器,在80端口接收所有的http請求,對本地能緩存的資源直接提供服務,否則轉發到upstream上的其他服務器處理,比如轉給fastDFS,或者是ATS等等,下面的nginx.conf是一個例子:

user  www www;
worker_processes  4;error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;pid        logs/nginx.pid;
worker_rlimit_nofile 65535;
google_perftools_profiles /tmp/tcmalloc;events {worker_connections  65535;
}http {include       mime.types;default_type  application/octet-stream;server_tokens off;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_names_hash_bucket_size 128;client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 50m;sendfile        on;tcp_nopush      on;tcp_nodelay     on;#keepalive_timeout  0;keepalive_timeout  60;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 256k;fastcgi_intercept_errors on;gzip  on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_types text/plain application/x-javascript text/css application/xml;gzip_vary on;upstream ats {server 127.0.0.1:8081;}server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;proxy_pass http://ats$request_uri;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;expires 2h;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location /test-js {root html;try_files $uri /;expires 10d;}location /test-img {root html;try_files $uri /;expires 10d;}location /test-html {root html;try_files $uri /;expires 10d;}# just use for taoyx testlocation /taoyx-test {root html;}# just for tulu testlocation /tulu {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {root           html;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;include        fastcgi_params;}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443;#    server_name  localhost;#    ssl                  on;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_timeout  5m;#    ssl_protocols  SSLv2 SSLv3 TLSv1;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers   on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

我現在在根目錄下存放一個ico文件,如何讓Nginx直接去本地拿這個文件,而不轉發給其他服務器呢?直接在nginx.conf中增加下面一行就可以了:

        # set site faviconlocation /favicon.ico {root html;}
下面按照我的配置,訪問Nginx的歡迎頁面就可以正常看到ico圖標了:



總結

以上是生活随笔為你收集整理的不能忽略的Nginx做web服务器的favicon.ico图像找不到问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。