nginx官网配置

https://www.nginx.com/resources/wiki/start/topics/examples/full/

(总结)Nginx配置文件nginx.conf中文详解


http://www.ha97.com/5194.html

 

nginx安装部署


http://blog.csdn.net/dutsoft/article/details/50595332

4.常用配置

<code class="hljs nginx has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#nginx运行用户和组</span>
<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">user</span>    www www;
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#启动进程,通常设置成和cpu的数量相等</span>
<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">worker_processes</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span>;
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#全局错误日志及PID文件</span>
<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">pid</span> /var/run/nginx.pid;
<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">error_log</span>  /var/log/nginx/error.log;

<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">events</span> {
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能</span>
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">use</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">epoll</span>;
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#单个后台worker process进程的最大并发链接数</span>
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">worker_connections</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10240</span>;
}
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#设定http服务器,利用它的反向代理功能提供负载均衡支持</span>
<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">http</span> {
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">include</span>       mime.types;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">default_type</span>  application/octet-stream;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">error_page</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">400</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">403</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">500</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">502</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">503</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">504</span>  /50x.html;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">index</span> index.html index.shtml
        autoindex <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">fastcgi_intercept_errors</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">on</span>;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">sendfile</span>        <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">on</span>;
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># These are good default values.</span>
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">tcp_nopush</span>      <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">on</span>;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">tcp_nodelay</span>     <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;

        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># output compression saves bandwidth</span>
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">gzip</span>  <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#gzip_static on;</span>
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#gzip_min_length  1k;</span>
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">gzip_http_version</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">gzip_comp_level</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">gzip_buffers</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16k</span>;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">gzip_proxied</span> any;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">gzip_disable</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"MSIE [1-6]\."</span>;
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">gzip_types</span>  text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#gzip_vary on;</span>

        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server_name_in_redirect</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;

        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#设定负载均衡的服务器列表</span>
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">upstream</span> portals {
                  <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">172.16.68.134:8082</span> max_fails=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> fail_timeout=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30s</span>;
                  <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">172.16.68.135:8082</span> max_fails=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> fail_timeout=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30s</span>;
                            <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">172.16.68.136:8082</span> max_fails=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> fail_timeout=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30s</span>;
                  <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">172.16.68.137:8082</span> max_fails=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> fail_timeout=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30s</span>;
        }

        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#upstream overflow {</span>
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       server 10.248.6.34:8090 max_fails=2 fail_timeout=30s;       </span>
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       server 10.248.6.45:8080 max_fails=2 fail_timeout=30s;       </span>
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#}</span>

        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server</span> {
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#侦听8080端口</span>
                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">listen</span>       <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8080</span>;
                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server_name</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">127.0.0.1</span>;
                   <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#403、404页面重定向地址</span>
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">error_page</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">403</span> = <span class="hljs-url" style="box-sizing: border-box;">http://www.e100.cn/ebiz/other/217/403.html</span>;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">error_page</span>  <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">404</span> = <span class="hljs-url" style="box-sizing: border-box;">http://www.e100.cn/ebiz/other/218/404.html</span>;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_connect_timeout</span>      <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">90</span>;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_send_timeout</span>         <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">180</span>;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_read_timeout</span>         <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">180</span>;

                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_buffer_size</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64k</span>;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_buffers</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128k</span>;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_busy_buffers_size</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128k</span>;


                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">client_header_buffer_size</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16k</span>;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">large_client_header_buffers</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64k</span>;

                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#proxy_send_timeout         3m;</span>
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#proxy_read_timeout         3m;</span>
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#proxy_buffer_size          4k;</span>
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#proxy_buffers              4 32k;</span>

                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_set_header</span> Host <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$http_host</span>;
                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_max_temp_file_size</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#proxy_hide_header Set-Cookie;</span>

         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       if ($host != 'www.e100.cn' ) {</span>
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#                rewrite ^/(.*)$ http://www.e100.cn/$1 permanent;</span>
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       }</span>


               <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> / {
                       <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">deny</span> all;
               }

                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">~ ^/resource/res/img/blue/space.gif</span> {
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_pass</span> <span class="hljs-url" style="box-sizing: border-box;">http://tecopera</span>;
               }

               <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> = / {
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">rewrite</span><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;"> ^(.*)$</span>  /ebiz/event/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">517</span>.html <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">last</span>;
               }



                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> = /ebiz/event/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">517</span>.html {
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">add_header</span> Vary Accept-Encoding;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /data/web/html;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">expires</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10m</span>;
               }




               <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> = /check.html {
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /usr/local/nginx/html/;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">access_log</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;
               }

               <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> = /50x.html {
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /usr/local/nginx/html/;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">expires</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1m</span>;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">access_log</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;
               }


              <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> = /index.html {
                       <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">add_header</span> Vary Accept-Encoding;
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#定义服务器的默认网站根目录位置</span>
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /data/web/html/ebiz;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">expires</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10m</span>;
               }
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#定义反向代理访问名称</span>
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">~ ^/ecps-portal/*</span> {
                   <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># expires 10m;</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#重定向集群名称</span>
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_pass</span> <span class="hljs-url" style="box-sizing: border-box;">http://portals</span>;
                    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#proxy_pass http://172.16.68.134:8082;</span>
               }

                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">~ ^/fetionLogin/*</span> {
                   <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># expires 10m;</span>
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">proxy_pass</span> <span class="hljs-url" style="box-sizing: border-box;">http://portals</span>;
                    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#proxy_pass http://172.16.68.134:8082;</span>
                }

                   <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#location  ~ ^/business/* {                                                                      </span>
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#   # expires 10m;                                                                                </span>
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#    proxy_pass http://172.16.68.132:8088;                                                                   </span>
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#    #proxy_pass http://172.16.68.134:8082;                                                       </span>
                <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#}</span>

                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">~ ^/rsmanager/*</span> {
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">expires</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10m</span>;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /data/web/;
                    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#proxy_pass http://rsm;</span>
               }
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#定义nginx处理的页面后缀</span>
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">~* (.*)\.(jpg|gif|htm|html|png|js|css)$</span>  {
                            <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /data/web/html/;
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#页面缓存时间为10分钟</span>
                         <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">expires</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10m</span>;
                   }

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#设定查看Nginx状态的地址     </span>
               <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">~* ^/NginxStatus/</span> {
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">stub_status</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">on</span>;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">access_log</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">allow</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10.1.252.126</span>;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">allow</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10.248.6.49</span>;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">allow</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">127.0.0.1</span>;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">deny</span> all;
               }
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       error_page   405 =200 @405;</span>
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       location @405</span>
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       {</span>
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#                proxy_pass http://10.248.6.45:8080;</span>
         <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       }  </span>

               <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">access_log</span>  /data/logs/nginx/access.log combined;
               <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">error_log</span>   /data/logs/nginx/error.log;
        }
         <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server</span> {
                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">listen</span>       <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8082</span>;

                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server_name</span>  _;
               <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> = /check.html {
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /usr/local/nginx/html/;
                    <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">access_log</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;
               }

        }
         <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server</span> {
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">listen</span>       <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8088</span>;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server_name</span>  _;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">~ ^/*</span> {
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /data/web/b2bhtml/;
                   <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">access_log</span> <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">off</span>;
         }                
         }
        <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server</span> {
                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">listen</span>       <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9082</span>;
                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">server_name</span>  _;

        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#        location ~ ^/resource/* {</span>
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#        expires 10m;</span>
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#        root /data/web/html/;</span>
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#       }</span>

                <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">location</span>  / {
                     <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">root</span> /data/web/html/sysMaintain/;
                       <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">if</span> (!-f <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">$request_filename</span>) {
                            <span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">rewrite</span><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;"> ^/(.*)$</span> /sysMaintain.html <span class="hljs-built_in" style="color: rgb(155, 133, 157); box-sizing: border-box;">last</span>;
                           }
                }
        }

}</code>

 

Nginx1.8.1+Tomcat7.0负载均衡


http://blog.csdn.net/IsResultXaL/article/details/50684273

nginx.conf

user       www www;  ## Default: nobody
worker_processes  5;  ## Default: 1
error_log  logs/error.log;
pid        logs/nginx.pid;
worker_rlimit_nofile 8192;

events {
  worker_connections  4096;  ## Default: 1024
}

http {
  include    conf/mime.types;
  include    /etc/nginx/proxy.conf;
  include    /etc/nginx/fastcgi.conf;
  index    index.html index.htm index.php;

  default_type application/octet-stream;
  log_format   main '$remote_addr - $remote_user [$time_local]  $status '
    '"$request" $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log   logs/access.log  main;
  sendfile     on;
  tcp_nopush   on;
  server_names_hash_bucket_size 128; # this seems to be required for some vhosts

  server { # php/fastcgi
    listen       80;
    server_name  domain1.com www.domain1.com;
    access_log   logs/domain1.access.log  main;
    root         html;

    location ~ \.php$ {
      fastcgi_pass   127.0.0.1:1025;
    }
  }

  server { # simple reverse-proxy
    listen       80;
    server_name  domain2.com www.domain2.com;
    access_log   logs/domain2.access.log  main;

    # serve static files
    location ~ ^/(images|javascript|js|css|flash|media|static)/  {
      root    /var/www/virtual/big.server.com/htdocs;
      expires 30d;
    }

    # pass requests for dynamic content to rails/turbogears/zope, et al
    location / {
      proxy_pass      http://127.0.0.1:8080;
    }
  }

  upstream big_server_com {
    server 127.0.0.3:8000 weight=5;
    server 127.0.0.3:8001 weight=5;
    server 192.168.0.1:8000;
    server 192.168.0.1:8001;
  }

  server { # simple load balancing
    listen          80;
    server_name     big.server.com;
    access_log      logs/big.server.access.log main;

    location / {
      proxy_pass      http://big_server_com;
    }
  }
}

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_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffers           32 4k;

fastcgi_conf

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

fastcgi_index  index.php;

fastcgi_param  REDIRECT_STATUS    200;

mime_types

types {
  text/html                             html htm shtml;
  text/css                              css;
  text/xml                              xml rss;
  image/gif                             gif;
  image/jpeg                            jpeg jpg;
  application/x-javascript              js;
  text/plain                            txt;
  text/x-component                      htc;
  text/mathml                           mml;
  image/png                             png;
  image/x-icon                          ico;
  image/x-jng                           jng;
  image/vnd.wap.wbmp                    wbmp;
  application/java-archive              jar war ear;
  application/mac-binhex40              hqx;
  application/pdf                       pdf;
  application/x-cocoa                   cco;
  application/x-java-archive-diff       jardiff;
  application/x-java-jnlp-file          jnlp;
  application/x-makeself                run;
  application/x-perl                    pl pm;
  application/x-pilot                   prc pdb;
  application/x-rar-compressed          rar;
  application/x-redhat-package-manager  rpm;
  application/x-sea                     sea;
  application/x-shockwave-flash         swf;
  application/x-stuffit                 sit;
  application/x-tcl                     tcl tk;
  application/x-x509-ca-cert            der pem crt;
  application/x-xpinstall               xpi;
  application/zip                       zip;
  application/octet-stream              deb;
  application/octet-stream              bin exe dll;
  application/octet-stream              dmg;
  application/octet-stream              eot;
  application/octet-stream              iso img;
  application/octet-stream              msi msp msm;
  audio/mpeg                            mp3;
  audio/x-realaudio                     ra;
  video/mpeg                            mpeg mpg;
  video/quicktime                       mov;
  video/x-flv                           flv;
  video/x-msvideo                       avi;
  video/x-ms-wmv                        wmv;
  video/x-ms-asf                        asx asf;
  video/x-mng                           mng;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值