本文主要讲述Nginx静态文件,怎样创建Nginx静态文件项目。这些内容都是一些门户网站和技术论坛找到的,中间可能有不少错误是我没有挑出的,欢迎大家 指正。

我们的目标是配置一个服务最快且cpu/io利用最有效的服务器,更重要的是一个安全的web服务器,下面的配置文件适用于最新版Nginx

  1. #######################################################

  2. ### Calomel.org /etc/Nginx.conf BEGIN

  3. #######################################################

  4. #

  5. pid /var/run/Nginx.pid;

  6. user Nginx Nginx;

  7. worker_processes 2;

  8. events {

  9. worker_connections 1024;

  10. }

  11. http {

  12. ## MIME types

  13. include mime.types;

  14. # types {

  15. # p_w_picpath/gif gif;

  16. # p_w_picpath/jpeg jpg;

  17. # p_w_picpath/png png;

  18. # p_w_picpath/bmp bmp;

  19. # p_w_picpath/x-icon ico;

  20. # text/css css;

  21. # text/html html;

  22. # text/plain bob;

  23. # text/plain txt;

  24. }

  25. default_type application/octet-stream;

  26. ## Size Limits

  27. client_body_buffer_size 8k;

  28. client_header_buffer_size 1k;

  29. client_max_body_size 1k;

  30. large_client_header_buffers 1 1k;

  31. ## Timeouts

  32. client_body_timeout 5;

  33. client_header_timeout 5;

  34. keepalive_timeout 5 5;

  35. send_timeout 5;

  36. ## General Options

  37. ignore_invalid_headers on;

  38. limit_zone gulag $binary_remote_addr 1m;

  39. recursive_error_pages on;

  40. sendfile on;

  41. server_name_in_redirect off;

  42. server_tokens off;

  43. ## TCP options

  44. tcp_nodelay on;

  45. tcp_nopush on;

  46. ## Compression

  47. gzip on;

  48. gzip_static on;

  49. gzip_buffers 16 8k;

  50. gzip_comp_level 9;

  51. gzip_http_version 1.0;

  52. gzip_min_length 0;

  53. gzip_types text/plain text/html text/css p_w_picpath/x-icon p_w_picpath/
    bmp;

  54. gzip_vary on;

  55. ## Log Format

  56. log_format main '$remote_addr $host $remote_user [$time_
    local] "$request" '

  57. '$status $body_bytes_sent "$http_referer" "$http_user_
    agent" "$gzip_ratio"';

  58. ## Deny access to any host other than (www.)mydomain.com

  59. server {

  60. server_name _; #default

  61. return 444;

  62. }

  63. ## Server (www.)mydomain.com

  64. server {

  65. access_log /var/log/Nginx/access.log main buffer=32k;

  66. error_log /var/log/Nginx/error.log info;

  67. expires 31d;

  68. limit_conn gulag 5;

  69. listen 127.0.0.1:8080 rcvbuf=64k backlog=128;

  70. root /disk01/htdocs;

  71. server_name mydomain.com www.mydomain;

  72. ## SSL Options (only enable if you use a SSL certificate)

  73. # ssl on;

  74. # ssl_certificate /ssl_keys/mydomain.com_ssl.crt;

  75. # ssl_certificate_key /ssl_keys/mydomain_ssl.key;

  76. # ssl_ciphers HIGH:!ADH:!MD5;

  77. # ssl_prefer_server_ciphers on;

  78. # ssl_protocols SSLv3;

  79. # ssl_session_cache shared:SSL:1m;

  80. # ssl_session_timeout 5m;

  81. ## Only allow GET and HEAD request methods

  82. if ($request_method !~ ^(GET|HEAD)$ ) {

  83. return 444;

  84. }

  85. ## Deny illegal Host headers

  86. if ($host !~* ^(mydomain.com|www.mydomain.com)$ ) {

  87. return 444;

  88. }

  89. ## Deny certain User-Agents (case insensitive)

  90. ## The ~* makes it case insensitive as opposed to just a ~

  91. if ($http_user_agent ~* (Baiduspider|Jullo) ) {

  92. return 444;

  93. }

  94. ## Deny certain Referers (case insensitive)

  95. ## The ~* makes it case insensitive as opposed to just a ~

  96. if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|
    love|nudit|organic|poker|porn|poweroversoftware|sex|teen|
    video|webcam|zippo) ) {

  97. return 444;

  98. }

  99. ## Redirect from www to non-www

  100. if ($host = 'www.mydomain.com' ) {

  101. rewrite ^/(.*)$ http://mydomain.com/$1 permanent;

  102. }

  103. ## Stop Image and Document Hijacking

  104. location ~* (\.jpg|\.png|\.css)$ {

  105. if ($http_referer !~ ^(http://mydomain.com) ) {

  106. return 444;

  107. }

  108. }

  109. ## Restricted Access directory

  110. location ^~ /secure/ {

  111. allow 127.0.0.1/32;

  112. allow 10.10.10.0/24;

  113. deny all;

  114. auth_basic "RESTRICTED ACCESS";

  115. auth_basic_user_file /var/www/htdocs/secure/access_list;

  116. }

  117. ## Only allow these file types to document root

  118. location / {

  119. if ($request_uri ~* (^\/|\.html|\.jpg|\.org|\.png|\.css|
    favicon\.ico|robots\.txt)$ ) {

  120. break;

  121. }

  122. return 444;

  123. }

  124. ## Serve an empty 1x1 gif _OR_ an error 204 (No Content) 
    for favicon.ico

  125. location = /favicon.ico {

  126. #empty_gif;

  127. return 204;

  128. }

  129. ## System Maintenance (Service Unavailable)

  130. if (-f $document_root/system_maintenance.html ) {

  131. error_page 503 /system_maintenance.html;

  132. return 503;

  133. }

  134. ## All other errors get the generic error page

  135. error_page 400 401 402 403 404 405 406 407 408 409 410 411 
    412 413 414 415 416 417

  136. 500 501 502 503 504 505 /error_page.html;

  137. location /error_page.html {

  138. internal;

  139. }

  140. }

  141. }

  142. #

  143. #######################################################

  144. ### Calomel.org /etc/Nginx.conf END

  145. #######################################################

以上就是对Nginx静态文件命令的详细介绍希望大家有所收获。

转载于:https://blog.51cto.com/lucifer119/1425099

Nginx静态文件的配置与安全认定相关推荐

  1. Nginx静态文件路径配置

    root目录与alias目录的区别 Nginx路径location配置中,使用root目录与alias目录的区别 1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接 ...

  2. Nginx缓存、静态文件缓存配置

    Nginx静态Server基本配置 server {listen 80; #监听的端口server_name www.test.com; #监听的域名charset utf-8;#编码root /us ...

  3. 各种 django 静态文件的配置总结【待续】

    2019独角兽企业重金招聘Python工程师标准>>> 最近在学习django框架的使用,想引用静态css文件,怎么都引用不到,从网搜了好多,大多因为版本问题, 和我现在的使用的da ...

  4. Nginx日志文件的配置

    Nginx日志文件的配置 Nginx的日志文件,默认在Nginx程序安装目录的logs二级目录下. 与Nginx日志相关的指令有两条 log_format,用来设置日志的记录格式. Access_lo ...

  5. Flask框架的学习——04—(模版继承、静态文件的配置、豆瓣APP界面案例实现)

    1.模版继承 Flask中的模板可以继承,通过继承可以把模板中许多重复出现的元素抽取出来,放在父模板中,并且父模板通过定义block给子模板开一个口,子模板根据需要,再实现这个block,假设现在有一 ...

  6. doraemon的python(大更新) django静态文件的配置(出错多的地方)

    ### 12.2 静态文件的使用#### 12.2.1静态文件的配置和使用 settings.py```python STATIC_URL = '/static/' #别名 STATICFILES_D ...

  7. nginx 静态文件缓存

    目的: 缓存nginx服务器的静态文件.如css,js,htm,html,jpg,gif,png,flv,swf,这些文件都不是经常更新.便于缓存以减轻服务器的压力. 实现: nginx proxy_ ...

  8. Nginx静态资源优化配置之tcp_nopush和tcp_nodelay

    (2)tcp_nopush:该指令必须在sendfile打开的状态下才会生效,主要是用来提升网络包的传输'效率' 语法 tcp_nopush on|off; 默认值 tcp_nopush off; 位置 ...

  9. Nginx静态资源优化配置之sendfile

    静态资源优化配置语法 Nginx对静态资源如何进行优化配置.这里从三个属性配置进行优化: sendfile on; tcp_nopush on; tcp_nodeplay on; (1)sendfile ...

最新文章

  1. 双重指针作为函数参数的妙用
  2. jQuery实现表格拖动排序
  3. 关于oracle中table函数的使用
  4. java int.parse_java数据类型转换,parseXXX(String)或valueOf(String)有什么区别?
  5. Spark Streaming从Kafka中获取数据,并进行实时单词统计,统计URL出现的次数
  6. C# 图片、文件等加入Project Resources
  7. photoshop问题
  8. Linux shell脚本启动 停止 重启jar包
  9. android 加载图片并在上面画图
  10. SQL Server 索引结构及其使用
  11. 2016年3例严重工控安全事故经验教训总结
  12. jQuery实现tab选项卡
  13. 计算机二级java判卷标准_计算机等级考试二级评分标准
  14. 《统计学》第八版贾俊平第三章课后答案Excel
  15. CCF 201903-1 小中大
  16. linux 如何加密文件夹,如何加密个别文件夹?
  17. Seaborn使用violinplot函数可视化分组小提琴图(violin plot)、使用inner函数设置在小提琴图中使用虚线显示分位数位置(inner = ‘quartile‘)
  18. Android 一个改善的okHttp封装库
  19. 西安交通大学城市学院计算机二级,西安交通大学城市学院计算机系举行考研经验分享交流会...
  20. EXCL模板报盘数据导入

热门文章

  1. mysql data文件夹下的ibdata1 文件作用
  2. 3.ELK 之elasticsearch CRUD
  3. Hive存储过程实现-hpsql
  4. 35. Search Insert Position
  5. TCP/IP详解学习笔记(12)-TCP的超时与重传
  6. Python数据类型之字符串
  7. HTML5 组件Canvas实现图像灰度化
  8. jQuery Masonry 一个 jQuery动态网格布局的插件
  9. Datatable中对某列求和,三种不同情况下的方法 .
  10. 在请求和响应中使用 XML