温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nginx中怎么配置静态文件

发布时间:2021-07-19 15:21:13 阅读:339 作者:Leah 栏目:web开发
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

本篇文章为大家展示了Nginx中怎么配置静态文件,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

#######################################################  ### Calomel.org /etc/Nginx.conf BEGIN  #######################################################  #  pid /var/run/Nginx.pid;  user Nginx Nginx;  worker_processes 2;  events {  worker_connections 1024;  }  http {  ## MIME types  include mime.types;  # types {  # image/gif gif;  # image/jpeg jpg;  # image/png png;  # image/bmp bmp;  # image/x-icon ico;  # text/css css;  # text/html html;  # text/plain bob;  # text/plain txt;  }  default_type application/octet-stream;  ## Size Limits  client_body_buffer_size 8k;  client_header_buffer_size 1k;  client_max_body_size 1k;  large_client_header_buffers 1 1k;  ## Timeouts   client_body_timeout 5;  client_header_timeout 5;  keepalive_timeout 5 5;  send_timeout 5;  ## General Options  ignore_invalid_headers on;  limit_zone gulag $binary_remote_addr 1m;  recursive_error_pages on;  sendfile on;  server_name_in_redirect off;  server_tokens off;  ## TCP options   tcp_nodelay on;  tcp_nopush on;  ## Compression  gzip on;  gzip_static on;  gzip_buffers 16 8k;  gzip_comp_level 9;  gzip_http_version 1.0;  gzip_min_length 0;  gzip_types text/plain text/html text/css image/x-icon image/bmp;  gzip_vary on;  ## Log Format  log_format main '$remote_addr $host $remote_user [$time_local"$request" '  '$status $body_bytes_sent "$http_referer" "$http_user_agent" "$gzip_ratio"';  ## Deny access to any host other than (www.)mydomain.com  server {  server_name _; #default  return 444;  }  ## Server (www.)mydomain.com  server {  access_log /var/log/Nginx/access.log main buffer=32k;  error_log /var/log/Nginx/error.log info;  expires 31d;  limit_conn gulag 5;  listen 127.0.0.1:8080 rcvbuf=64k backlog=128;  root /disk01/htdocs;  server_name mydomain.com www.mydomain;  ## SSL Options (only enable if you use a SSL certificate)  # ssl on;  # ssl_certificate /ssl_keys/mydomain.com_ssl.crt;  # ssl_certificate_key /ssl_keys/mydomain_ssl.key;  # ssl_ciphers HIGH:!ADH:!MD5;  # ssl_prefer_server_ciphers on;  # ssl_protocols SSLv3;  # ssl_session_cache shared:SSL:1m;  # ssl_session_timeout 5m;  ## Only allow GET and HEAD request methods  if ($request_method !~ ^(GET|HEAD)$ ) {  return 444;  }  ## Deny illegal Host headers  if ($host !~* ^(mydomain.com|www.mydomain.com)$ ) {  return 444;  }  ## Deny certain User-Agents (case insensitive)  ## The ~* makes it case insensitive as opposed to just a ~  if ($http_user_agent ~* (Baiduspider|Jullo) ) {  return 444;  }  ## Deny certain Referers (case insensitive)  ## The ~* makes it case insensitive as opposed to just a ~  if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|sex|teen|video|webcam|zippo) ) {  return 444;  }  ## Redirect from www to non-www  if ($host = 'www.mydomain.com' ) {  rewrite ^/(.*)$ http://mydomain.com/$1 permanent;  }  ## Stop Image and Document Hijacking  location ~* (\.jpg|\.png|\.css)$ {  if ($http_referer !~ ^(http://mydomain.com) ) {  return 444;  }  }  ## Restricted Access directory  location ^~ /secure/ {  allow 127.0.0.1/32;  allow 10.10.10.0/24;  deny all;  auth_basic "RESTRICTED ACCESS";  auth_basic_user_file /var/www/htdocs/secure/access_list;  }  ## Only allow these file types to document root  location / {  if ($request_uri ~* (^\/|\.html|\.jpg|\.org|\.png|\.css|favicon\.ico|robots\.txt)$ ) {  break;  }  return 444;  }  ## Serve an empty 1x1 gif _OR_ an error 204 (No Content) for favicon.ico  location = /favicon.ico {  #empty_gif;  return 204;  }  ## System Maintenance (Service Unavailable)   if (-f $document_root/system_maintenance.html ) {  error_page 503 /system_maintenance.html;  return 503;  }  ## All other errors get the generic error page  error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417  500 501 502 503 504 505 /error_page.html;  location /error_page.html {  internal;  }  }  }  #  #######################################################  ### Calomel.org /etc/Nginx.conf END  #######################################################  

上述内容就是Nginx中怎么配置静态文件,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×