IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機(jī)版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置: 首頁操作系統(tǒng)LINUX → nginx關(guān)于服務(wù)靜態(tài)文件的配置

nginx關(guān)于服務(wù)靜態(tài)文件的配置

時(shí)間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評(píng)論(1)

  我們的目標(biāo)是配置一個(gè)服務(wù)最快且cpu/io利用最有效的服務(wù)器,更重要的是一個(gè)安全的web服務(wù)器,下面的配置文件適用于最新版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

  #######################################################

  2. nginx關(guān)于對(duì)后端服務(wù)器的反向代理配置

  有三個(gè)后端服務(wù),一個(gè)為web內(nèi)容服務(wù),一個(gè)是論壇服務(wù),一個(gè)為文件服務(wù)。

  當(dāng)一個(gè)請(qǐng)求來時(shí),nginx代理服務(wù)器其查看url把請(qǐng)求定向到相應(yīng)的服務(wù)器,這個(gè)配置也緩沖文件服務(wù)的內(nèi)容,但是論壇的和數(shù)據(jù)下載的內(nèi)容就不緩存了,這個(gè)配置也使用了壓縮,更好的節(jié)省內(nèi)存

  寫道

  #######################################################

  ### Calomel.org /etc/nginx.conf BEGIN

  #######################################################

  pid /var/run/nginx.pid;

  user nginx nginx;

  worker_processes 10;

  events {

  worker_connections 1024;

  }

  http {

  ## MIME types

  #include /etc/nginx_mime.types;

  default_type application/octet-stream;

  ## Size Limits

  client_body_buffer_size 128K;

  client_header_buffer_size 128K;

  client_max_body_size 1M;

  large_client_header_buffers 1 1k;

  ## Timeouts

  client_body_timeout 60;

  client_header_timeout 60;

  expires 24h;

  keepalive_timeout 60 60;

  send_timeout 60;

  ## General Options

  ignore_invalid_headers on;

  keepalive_requests 100;

  limit_zone gulag $binary_remote_addr 5m;

  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_buffers 16 8k;

  gzip_comp_level 6;

  gzip_http_version 1.0;

  gzip_min_length 0;

  gzip_types text/plain text/css image/x-icon application/x-perl application/x-httpd-cgi;

  gzip_vary on;

  ## Log Format

  log_format main '$remote_addr $host $remote_user [$time_local] "

關(guān)鍵詞標(biāo)簽:nginx

相關(guān)閱讀

文章評(píng)論
發(fā)表評(píng)論

熱門文章 安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程 安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程 Tomcat9.0如何安裝_Tomcat9.0環(huán)境變量配置方法 Tomcat9.0如何安裝_Tomcat9.0環(huán)境變量配置方法 多種操作系統(tǒng)NTP客戶端配置 多種操作系統(tǒng)NTP客戶端配置 Linux操作系統(tǒng)修改IP Linux操作系統(tǒng)修改IP

相關(guān)下載

    人氣排行 Linux下獲取CPUID、硬盤序列號(hào)與MAC地址 dmidecode命令查看內(nèi)存型號(hào) linux tc實(shí)現(xiàn)ip流量限制 安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程 linux下解壓rar文件 lcx.exe、nc.exe、sc.exe入侵中的使用方法 Ubuntu linux 關(guān)機(jī)、重啟、注銷 命令 查看linux服務(wù)器硬盤IO讀寫負(fù)載