Nginx地图服务器及负载均衡配置说明

Nginx地图服务器及负载均衡配置说明

配置文件在nginx目录下conf—>nginx.conf;

原始配置文件内容如下:

#user nobody;

worker_processes  1;

#error_log logs/error.log;

#error_log logs/error.log  notice;

#error_log logs/error.log  info;

#pid       logs/nginx.pid;

events {

   worker_connections  1024;

}

http {

   include       mime.types;

   default_type application/octet-stream;

   #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;

   sendfile        on;

   #tcp_nopush     on;

   #keepalive_timeout  0;

   keepalive_timeout  65;

   #gzip  on;

   server {

       listen       80;

       server_name  localhost;

       #charset koi8-r;

       #access_log logs/host.access.log  main;

       location / {

           root   html;

           index  index.html index.htm;

       }

       #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;

       }

       # 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  /scripts$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 ssl;

   #    server_name  localhost;

   #    ssl_certificate      cert.pem;

   #    ssl_certificate_key  cert.key;

   #    ssl_session_cache    shared:SSL:1m;

   #    ssl_session_timeout  5m;

   #    ssl_ciphers  HIGH:!aNULL:!MD5;

   #   ssl_prefer_server_ciphers  on;

   #    location / {

   #        root   html;

   #        index  index.html index.htm;

   #    }

    #}

}

一、     地图服务器配置说明

worker_connections  1024;         默认请求的并发数,值越大并发越高

1.图片服务器主要配置项

   在http下server 中配置如下项:

      localhost /tiles/{

              root  html;

      }

说明:localhost后面匹配 url路径

/tiles/  图片请求地址,注意前后都要有“/”

root  html; 图片请求的根目录

注意事项:

         localhost后匹配路径需要与项目下地图图片请求路径一致,例如:

     地图请求路径为 http://192.168.1.3:8000/tiles 则localhost后匹配路径为 /tiles/

     地图请求路径在项目下webroot à baidu_map_v2.0 à baidumap_offline_v2_load.js中bdmapcfg配置项tiles_dir.

二、     负载均衡配置说明

1.在http下server 中配置如下项:

localhost / {

            proxy_passhttp://localhost;

}

2. 在http下配置如下项:

   upstream localhost{

                  ip_hash;

                  server 192.168.1.12:8080;

server192.168.1.13:8000;

server192.168.1.13:8090;

   }

说明:ip_hash 保证同一客户端请求固定的服务器可解决session问题

注意事项:

  proxy_pass http后的路径必须与upstream后的名字一致

以上为nginx最基本配置,仅供参考。

猜你喜欢

转载自blog.csdn.net/qq_20565329/article/details/80494077