日期:2012-03-31 23:28:00  来源:本站整理

Nginx搭建负载均衡服务器(二)[服务器安全]

赞助商链接



  本文“Nginx搭建负载均衡服务器(二)[服务器安全]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

  (4)配置主配置文件

  vim /usr/local/nginx/conf/nginx.conf

  1

  2 user nobody;

  3 worker_processes 1;

  4

  5 #error_log logs/error.log;

  6 #error_log logs/error.log notice;

  7 error_log logs/error.log debug;

  8

  9 pid logs/nginx.pid;

  10

  11

  12 events {

  13 use epoll;

  14 worker_connections 1024;

  15 }

  16

  17

  18 http {

  19 include mime.types;

  20 default_type application/octet-stream;

  21

  22 log_format main '$remote_addr - $remote_user [$time_local] "$request" '

  23 '$status $body_bytes_sent "$http_referer" '

  24 '"$http_user_agent" "$http_x_forwarded_for"';

  25

  26 access_log logs/access.log main;

  27

  28 sendfile on;

  29 #tcp_nopush on;

  30

  31 #keepalive_timeout 0;

  32 keepalive_timeout 65;

  33 --------------------------------------------------------------------------------------------------------------------

  34 gzip on;

  35 gzip_min_length 1k;

  36 gzip_buffers 6 16k;

  37 gzip_http_version 1.1;

  38 gzip_comp_level 2;

  39 gzip_types text/plain application/x-javascript text/css application/xml;

  40 gzip_vary on;

  ---------------------------------------------------------------------------------------------------------------------

  41 # server {

  42 # listen 80;

  43 # server_name localhost;

  44

  45 #charset koi8-r;

  46

  47 #access_log logs/host.access.log main;

  48

  49 # location / {

  50 # root html;

  51 # index index.html index.htm;

  52 # }

  53

  54 error_page 404 /404.html;

  55

  56 # redirect server error pages to the static page /50x.html

  57 #

  58 # error_page 500 502 503 504 /50x.html;

  59 # location = /50x.html {

  60 # root html;

  61 # }

  62

  63 # proxy the PHP scripts to Apache listening on 127.0.0.1:80

  64 #

  65 #location ~ \.php$ {

  66 # proxy_pass http://127.0.0.1;

  67 #}

  68

  69 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

  70 #

  71 #location ~ \.php$ {

  72 # root html;

  73 # fastcgi_pass 127.0.0.1:9000;

  74 # fastcgi_index index.php;

  75 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

  76 # include fastcgi_params;

  77 #}

  78

  79 # deny access to .htaccess files, if Apache's document root

  80 # concurs with nginx's one

  81 #

  82 #location ~ /\.ht {

  83 # deny all;

  84 #}

  85 }

  86

  87

  88 # another virtual host using mix of IP-, name-, and port-based configuration

  89 #

  90 #server {

  91 # listen 8000;

  92 # listen somename:8080;

  93 # server_name somename alias another.alias;

  94

  95 # location / {

  96 # root html;

  97 # index index.html index.htm;

  98 # }

  99 #}

  100

  101

  102 # HTTPS server

  103 #

  104 #server {

  105 # listen 443;

  106 # server_name localhost;

  107

  108 # ssl on;

  109 # ssl_certificate cert.pem;

  110 # ssl_certificate_key cert.key;

  111

  112 # ssl_session_timeout 5m;

  113

  114 # ssl_protocols SSLv2 SSLv3 TLSv1;

  115 # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

  116 # ssl_prefer_server_ciphers on;

  117

  118 # location / {

  119 # root html;

  120 # index index.html index.htm;

  121 # }

  122 #}

  123

  124 #}

  126 http

  127 {

  128 upstream www.test.com {

  129 server 192.168.1.125:80 weight=3 max_fails=3 fail_timeout=20s;

  130 server 192.168.1.126:80 weight=1 max_fails=3 fail_timeout=20s;

  131 server 192.168.1.121:80 weight=5 max_fails=3 fail_timeout=20s;

  132 }

  133

  134 server

  135 {

  136 listen 80;

  137 server_name www.test.com 192.168.1.120;

  138 index index.htm index.html;

  139 #root /web/wwwroot;

  140

  141 location / {

  142 proxy_pass http://www.test.com;

  143 proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;

  144 proxy_set_header Host $host;

  145 proxy_set_header X-Real-IP $remote_addr;

  146 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  147 include proxy.conf;

  148 }

  149 log_format blog_test_com '$remote_addr - $remote_user [$time_local] $request '

  150 '"$status" $body_bytes_sent "$http_referer" '

  151 '"$http_user_agent" "$http_x_forwarded_for"';

  152 access_log logs/blog_test_com;

  153 }

  154 }

  :wq 保存

  (5)配置proxy.conf文件

  vim /usr/local/nginx/conf/proxy.conf

  proxy_redirect off;

  proxy_set_header Host $host;

  proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  client_body_buffer_size 128k;

  proxy_connect_timeout 90;

  proxy_send_timeout 90;

  proxy_read_timeout 90;

  proxy_buffer_size 4k;

  proxy_buffers 6 32k;

  proxy_busy_buffers_size 64k;

  proxy_temp_file_write_size 64k;

  :wq 保存

  注明:到此nginx负载均衡已搭建完成,

  测试:http://www.test.com 就看可以拜候到


  以上是“Nginx搭建负载均衡服务器(二)[服务器安全]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
  • nginx后端安康监测
  • 织梦CMS安装利用教程 Win+Nginx+PHP+MySQL环境搭建
  • CentOS 下 Nginx + Keepalived 配置高可用Web站点
  • nginx服务器的安装和配置的办法介绍
  • CentOS6 yum搭建Linux+Nginx+PHP+MYSQL(LNMP)
  • 利用Nginx后如安在web利用中获得用户ip及原理注释
  • CentOS 6.2 安装Nginx并设置为开机服务
  • Nginx配置禁止通过IP拜候
  • Nginx + PHP 5.2.17(FastCGI) 502 Bad Gateway错误
  • nginx躲藏版本号
  • ubuntu 12.04 安装 Nginx+PHP5 (PHP-FPM) +MySQL主机详解
  • Nginx做web服务器linux内核参数优化
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .