<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运维博客 &#187; Nginx</title>
	<atom:link href="http://www.ywbk.cc/category/nginx/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ywbk.cc</link>
	<description>开发&#38;运维</description>
	<lastBuildDate>Thu, 28 May 2026 02:59:52 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.7.41</generator>
	<item>
		<title>Centos7下Nginx 配置 HTTPS教程</title>
		<link>http://www.ywbk.cc/1181.html</link>
		<comments>http://www.ywbk.cc/1181.html#comments</comments>
		<pubDate>Thu, 10 Aug 2023 08:32:25 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://www.05bd.com/?p=1181</guid>
		<description><![CDATA[1、安装Nginx 可以使用源码或者rpm方式，可以在本站搜索，这里不再赘述 2、检查Nginx是否安装SSL [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2>1、安装Nginx</h2>
<p>可以使用源码或者rpm方式，可以在本站搜索，这里不再赘述</p>
<h2>2、检查Nginx是否安装SSL 模块</h2>
<pre class="prettyprint linenums">/usr/local/nginx/sbin/nginx -V
#如果configure arguments中包含：with-http_ssl_module, 则已安装
#使用rom方式安装的nginx默认会装ssl模块，如果是编译安装的需要安装下</pre>
<h2>3、申请SSL证书</h2>
<p>有两种办法：<br />
1.正式环境：建议去购买ssl证书，或者去域名商领取免费的ssl证书<br />
2.测试环境：使用open ssl生成一个，浏览器会报错”不受信任的证书“，下面是命令：</p>
<pre class="prettyprint linenums">openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem 
#会在当前目录下生成 cert.pem 和 key.pem 两个文件，就是证书和密钥，后面用。</pre>
<h2>4、配置Nginx</h2>
<pre class="prettyprint linenums">vi /etc/nginx/conf.d/default.conf
#配置为如下格式，注意其中的ssl_certificate和ssl_certificate_key值改为上面的证书和密钥文件路径
server {
    listen       443 ssl;
    server_name  localhost;
    ssl_certificate     /root/cert.pem;
    ssl_certificate_key  /root/key.pem;
    ssl_session_timeout  5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
        location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}
server {
    listen       80;
    server_name  localhost;
    return 301 https://10.110.10.52;
}</pre>
<h2>4、重启Nginx</h2>
<pre class="prettyprint linenums">systemctl restart nginx
#如果报错提示：SSL: error:0200100D，应该是SELinux问题，关闭即可
#临时关闭
setenforce 0
#永久关闭
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
#设置后需要重启才能生效</pre>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/1181.html">Centos7下Nginx 配置 HTTPS教程</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/1181.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux CentOS7使用rpm方式安装nginx</title>
		<link>http://www.ywbk.cc/1035.html</link>
		<comments>http://www.ywbk.cc/1035.html#comments</comments>
		<pubDate>Fri, 03 Dec 2021 02:42:16 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://www.05bd.com/?p=1035</guid>
		<description><![CDATA[需要使用编译方式安装，清访问：Centos源码编译安装配置Nginx 1、查询是否已经安装了nginx rpm [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p>需要使用编译方式安装，清访问：<a href="http://www.05bd.com/11.html">Centos源码编译安装配置Nginx</a></p></blockquote>
<h2>1、查询是否已经安装了nginx</h2>
<pre class="prettyprint linenums">rpm -qa|grep nginx
#如果有安装了 ，执行rpm -e nginx卸载</pre>
<h2>2、下载nginx rpm包并安装</h2>
<pre class="prettyprint linenums">wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
#也可去http://nginx.org/packages/centos/7/x86_64/RPMS/找合适的版本
rpm -ivh nginx-1.18.0-1.el7.ngx.x86_64.rpm
#默认安装位置/etc/nginx/，配置文件/etc/nginx/nginx.conf
#如果提示需要依赖可以使用yum安装解决
yum install nginx-1.18.0-1.el7.ngx.x86_64.rpm</pre>
<h2>3、启动、重启、停止nginx</h2>
<pre class="prettyprint linenums">systemctl start nginx
systemctl status nginx
systemctl stop nginx</pre>
<h2>4、设置开机自启动</h2>
<pre class="prettyprint linenums">systemctl enable nginx
systemctl list-unit-files|grep nginx</pre>
<h2>5、关闭防火墙</h2>
<pre class="prettyprint linenums">#如果其他主机无法访问，需要关闭防火墙
systemctl stop firewalld
systemctl disable firewalld</pre>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/1035.html">Linux CentOS7使用rpm方式安装nginx</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/1035.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx中常用的内置变量</title>
		<link>http://www.ywbk.cc/842.html</link>
		<comments>http://www.ywbk.cc/842.html#comments</comments>
		<pubDate>Thu, 26 Dec 2019 06:06:28 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://www.05bk.com/?p=842</guid>
		<description><![CDATA[1. 从请求行中解析到的变量 以访问http://invo.com/nginx-var/request-lin [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2>1. 从请求行中解析到的变量</h2>
<p>以访问http://invo.com/nginx-var/request-line?a=1&amp;b=2得到的结果为例，invo.com为测试的虚拟主机</p>
<table border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col span="3" /> </colgroup>
<tbody>
<tr>
<td>变量</td>
<td>含义</td>
<td>示例</td>
</tr>
<tr>
<td>$request</td>
<td>整个请求行</td>
<td>GET /nginx-var/request-line?a=1&amp;b=2 HTTP/1.1</td>
</tr>
<tr>
<td>$request_method</td>
<td>请求方法（如GET、POST)</td>
<td>GET</td>
</tr>
<tr>
<td>$request_uri</td>
<td>完整的请求URI</td>
<td>/nginx-var/request-line?a=1&amp;b=2</td>
</tr>
<tr>
<td>$uri</td>
<td>URI，除去查询字符串</td>
<td>/nginx-var/request-line</td>
</tr>
<tr>
<td>$document_uri</td>
<td>同$uri</td>
<td>/nginx-var/request-line</td>
</tr>
<tr>
<td>$args</td>
<td>查询字符串</td>
<td>a=1&amp;b=2</td>
</tr>
<tr>
<td>$query_string</td>
<td>同$args</td>
<td>a=1&amp;b=2</td>
</tr>
<tr>
<td>$server_protocol</td>
<td>请求协议（如HTTP/1.0 HTTP/1.1)</td>
<td>HTTP/1.1</td>
</tr>
<tr>
<td>$arg_name</td>
<td>请求行中name参数的值</td>
<td>$arg_a = 1 , $arg_b = 2</td>
</tr>
</tbody>
</table>
<p>说明： 这些变量在配置文件中通常配合try_files指令和rewrite指令使用。</p>
<h2>2. 从请求头中解析到的变量</h2>
<p>用Firefox的HttpRequester插件，添加Cookie为CA=abc;CB=123，Referer为http://invo.com的请求头，<br />
以访问地址http://invo.com/nginx-var/header-var得到的结果为例。</p>
<table border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col span="3" /> </colgroup>
<tbody>
<tr>
<td>变量</td>
<td>含义</td>
<td>示例</td>
</tr>
<tr>
<td>$host</td>
<td>按如下顺序获得：</p>
<p>请求行中的host、请求头中的Host、</p>
<p>配置文件中匹配到的server_name</td>
<td>invo.com</td>
</tr>
<tr>
<td>$remote_addr</td>
<td>客户端ip地址</td>
<td>127.0.0.1</td>
</tr>
<tr>
<td>$remote_port</td>
<td>客户端端口</td>
<td>4204</td>
</tr>
<tr>
<td>$http_user_agent</td>
<td>用户代理（“User-Agent”请求头的值)</td>
<td>Mozilla/5.0 (Windows NT 6.1; rv:50.0)</p>
<p>Gecko/20100101 Firefox/50.0</td>
</tr>
<tr>
<td>$http_cookie</td>
<td>“Cookie”请求头的值</td>
<td>CA=abc;CB=123</td>
</tr>
<tr>
<td>$cookie_name</td>
<td>Cookie中名为name的值</td>
<td>$cookie_CA=abc, $cookie_CB=123</td>
</tr>
<tr>
<td>$http_referer</td>
<td>“Http-Referer”请求头的值</td>
<td>http://invo.com</td>
</tr>
</tbody>
</table>
<p>说明： $host、$remote_addr、$http_user_agent、$http_referer在配置文件中经常用到，可以根据这些变量来决定如何处理请求。以上变量也经常用在log_format指令中，这些变量的值将记录在日志文件，用于分析日志。有一次特意查看了下日志文件，发现同一个客户端每次请求服务器的端口（$remote_port）会变化，推断公司网络的类型为对称型NAT。</p>
<h2>3. 其它内置变量</h2>
<table border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col span="3" /> </colgroup>
<tbody>
<tr>
<td>变量</td>
<td>含义</td>
<td>示例</td>
</tr>
<tr>
<td>$body_bytes_sent</td>
<td>发给客户端的数据大小，以字节计，不包括http报头</td>
<td></td>
</tr>
<tr>
<td>$bytes_sent</td>
<td>发给客户端的数据大小，以字节计</td>
<td></td>
</tr>
<tr>
<td>$status</td>
<td>http响应状态码</td>
<td></td>
</tr>
<tr>
<td>$request_time</td>
<td>请求处理时间</td>
<td></td>
</tr>
<tr>
<td>$upstream_response_time</td>
<td>从与upstream建立连接到收到最后一个字节所经历的时间（nginx做反向代理服务器时可用）</td>
<td></td>
</tr>
<tr>
<td>$upstream_connect_time</td>
<td>与upstream建立连接所消耗的时间（nginx做反向代理服务器时可用）</td>
<td></td>
</tr>
</tbody>
</table>
<p>说明：以上变量通常用于日志配置中，用于统计流量和监视服务器性能。</p>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/842.html">Nginx中常用的内置变量</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/842.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx负载均衡配置——第三方模块方式</title>
		<link>http://www.ywbk.cc/360.html</link>
		<comments>http://www.ywbk.cc/360.html#comments</comments>
		<pubDate>Sat, 09 Dec 2017 14:07:19 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://05bk.com/?p=360</guid>
		<description><![CDATA[负载均衡（load-balance）就是将负载分摊到多个操作单元上执行，从而提高服务的可用性和响应速度，带给用 [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p>负载均衡（load-balance）就是将负载分摊到多个操作单元上执行，从而提高服务的可用性和响应速度，带给用户更好的体验。Nginx不仅可以作为一个Web服务器或反向代理服务器，还可以通过upstream指令实现配置负载均衡服务器组实现多种方式的负载均衡。4种典型方式：<a href="http://05bk.com/357.html" target="_blank">轮询方式</a>、<a href="http://05bk.com/358.html" target="_blank">权重方式</a>、<a href="http://05bk.com/359.html" target="_blank">ip_hash方式</a>、<a href="http://05bk.com/360.html" target="_blank">第三方模块方式</a>。</p></blockquote>
<p>第三方模块方式，Nginx本身不包含第三方模块的实现方式，需另外下载。常见的有fair(按照每台服务器的响应时间来分配请求，响应时间短的优先分配)和url_hash(按照访问url的hash值来分配请求),本文以fair为例。</p>
<h2>1.准备服务器</h2>
<p>准备3台虚拟机。其中两台用作后端Web服务器，IP分别为192.168.1.123和192.168.1.91，采用默认编译安装Nginx服务器即可。另外IP为192.168.1.141的服务器用作负载均衡服务器需要添加fair模块。下载<a href="https://github.com/gnosek/nginx-upstream-fair?spm=a2c4e.11153940.blogcont73621.10.752155b99QCNK3" target="_blank">nginxupstream-fair-master.zip</a>到root目录下并解压，然后编译nginx时候加上add-module选项，以下只列出关键步骤，其他安装步骤参考：<a href="http://05bk.com/11.html" target="_blank">源码编译安装Nginx</a></p>
<pre class="prettyprint linenums">unzip nginx-upstream-fair-master.zip
./configure --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/nginx-upstream-fair-master</pre>
<h2>2.配置负载均衡服务器nginx.conf</h2>
<pre class="prettyprint linenums">＃配置域名为test.com的主机
server {
    listen       80;
    server_name  test.com;
    location / {
        proxy_pass http://web_server;
    }
}
＃配置负载均衡服务器组名称和地址
upstream web_server {
    fair;
    server 192.168.1.123;
    server 192.168.1.91;
}</pre>
<h2>3.测试验证</h2>
<p>为了验证fair模块是否能够根据后端服务器的响应时间负载均衡，可以通过PHP延长服务器的响应时间。在Web服务器192.168.1.123中配置PHP后，编写index.php文件，内容如下：</p>
<pre class="prettyprint linenums">&lt;? php sleep (10); ?&gt;
192.168.1.123</pre>
<p>重启负载均衡服务器配置后，在其他机器上多次访问192.168.1.141输出的是一个固定IP，说明配置成功：</p>
<pre class="prettyprint linenums">curl 192.168.1.141
#输出192.168.1.91
……
curl 192.168.1.141
#输出192.168.1.9</pre>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/360.html">Nginx负载均衡配置——第三方模块方式</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/360.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx负载均衡配置——ip_hash方式</title>
		<link>http://www.ywbk.cc/359.html</link>
		<comments>http://www.ywbk.cc/359.html#comments</comments>
		<pubDate>Sun, 03 Dec 2017 13:32:55 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[负载均衡]]></category>

		<guid isPermaLink="false">http://05bk.com/?p=359</guid>
		<description><![CDATA[负载均衡（load-balance）就是将负载分摊到多个操作单元上执行，从而提高服务的可用性和响应速度，带给用 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="white-space: normal;">负载均衡（load-balance）就是将负载分摊到多个操作单元上执行，从而提高服务的可用性和响应速度，带给用户更好的体验。Nginx不仅可以作为一个Web服务器或反向代理服务器，还可以通过upstream指令实现配置负载均衡服务器组实现多种方式的负载均衡。4种典型方式：<a href="http://05bk.com/357.html" target="_blank">轮询方式</a>、<a href="http://05bk.com/358.html" target="_blank">权重方式</a>、<a href="http://05bk.com/359.html" target="_blank">ip_hash方式</a>、<a href="http://05bk.com/360.html" target="_blank">第三方模块方式</a>。</p>
<p style="white-space: normal;">ip_hash方式是按每个请求访问IP的hash结果分配，可以使每个访客固定访问一个后端服务器，可以解决Session共享的问题。</p>
<p style="white-space: normal;">1.准备服务器</p>
<p style="white-space: normal;">准备3台虚拟机，并全部安装Nginx服务器。可以参考：<a href="http://05bk.com/11.html" target="_blank">源码编译安装Nginx</a>，其中IP为192.168.1.141的服务器用作负载均衡服务器，另外两台用作后端Web服务器，IP分别为192.168.1.123和192.168.1.91</p>
<p style="white-space: normal;">2.配置负载均衡服务器nginx.conf</p>
<pre class="brush:bash;toolbar:false">＃配置域名为test.com的主机
server {
    listen       80;
    server_name  test.com;
    location / {
        proxy_pass http://web_server;
    }
}
＃配置负载均衡服务器组名称和地址
upstream web_server {
    ip_hash;
    server 192.168.1.123;
    server 192.168.1.91;
}</pre>
<p>在使用ip_hash方式处理负载均衡时，Web服务器的状态可以使用down(表示当前的server暂时不参与负载均衡),但是不能使用weight(权重)和backup(预留的备份机器)。</p>
<p style="white-space: normal;">3.配置WEB服务器组</p>
<p style="white-space: normal;">在Web服务器192.168.1.123中的网站目录下编写index.html，内容如下：</p>
<p style="white-space: normal;">192.168.1.123</p>
<p style="white-space: normal;">在Web服务器192.168.1.91中的网站目录下编写index.html，内容如下：</p>
<p style="white-space: normal;">192.168.1.91</p>
<p style="white-space: normal;">4.测试验证</p>
<p style="white-space: normal;">重启负载均衡服务器配置后，在其他机器上多次访问192.168.1.141输出的是一个固定IP，说明配置成功：</p>
<pre class="brush:bash;toolbar:false">curl 192.168.1.141
#输出192.168.1.91
……
curl 192.168.1.141
#输出192.168.1.91</pre>
<p>由于ip_hash方式为每一个用户IP绑定一个Web服务器处理，可能会导致某些Web服务器接收的请求多，某些Web服务器接到的请求少，无法保证Web服务器的负载均衡。 因此，建议只在必要的情况下使用这种方式。</p>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/359.html">Nginx负载均衡配置——ip_hash方式</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/359.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx负载均衡配置——权重方式</title>
		<link>http://www.ywbk.cc/358.html</link>
		<comments>http://www.ywbk.cc/358.html#comments</comments>
		<pubDate>Tue, 28 Nov 2017 13:13:52 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[负载均衡]]></category>

		<guid isPermaLink="false">http://05bk.com/?p=358</guid>
		<description><![CDATA[负载均衡（load-balance）就是将负载分摊到多个操作单元上执行，从而提高服务的可用性和响应速度，带给用 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="white-space: normal;">负载均衡（load-balance）就是将负载分摊到多个操作单元上执行，从而提高服务的可用性和响应速度，带给用户更好的体验。Nginx不仅可以作为一个Web服务器或反向代理服务器，还可以通过upstream指令实现配置负载均衡服务器组实现多种方式的负载均衡。4种典型方式：<a href="http://05bk.com/357.html" target="_blank">轮询方式</a>、<a href="http://05bk.com/358.html" target="_blank">权重方式</a>、<a href="http://05bk.com/359.html" target="_blank">ip_hash方式</a>、<a href="http://05bk.com/360.html" target="_blank">第三方模块方式</a>。</p>
<p style="white-space: normal;">权重方式是利用weight指定的权重比率，与访问率成正比，用于后端服务器性能不均的情况。</p>
<p style="white-space: normal;">1.准备服务器</p>
<p style="white-space: normal;">准备3台虚拟机，并全部安装Nginx服务器。可以参考：<a href="http://05bk.com/11.html" target="_blank">源码编译安装Nginx</a>，其中IP为192.168.1.141的服务器用作负载均衡服务器，另外两台用作后端Web服务器，IP分别为192.168.1.123和192.168.1.91</p>
<p style="white-space: normal;">2.配置负载均衡服务器nginx.conf</p>
<pre class="brush:bash;toolbar:false">＃配置域名为test.com的主机
server {
    listen       80;
    server_name  test.com;
    location / {
        proxy_pass http://web_server;
    }
}
＃配置负载均衡服务器组名称、地址、权重
upstream web_server {
        #weigrt权重值(越大访问率大),在fail_timeout时间内检查后端服务器max_fails次，失败则被剔除;
	server 192.168.1.123 weight=1 fail_timeout=30s max_fails=2;
	server 192.168.1.91 weight=1 fail_timeout=30s max_fails=2;
}
</pre>
<p>在上述配置中，weigth参数表示权值，权值越高则被分配到的概率越大。除此之外，还可以设定每台Web服务器在负载均衡调度中的状态，常用的参数：max_fails允许请求失败的次数默认为l、fail_timeoutq请求失败后暂停服务的时间、backup预留的备份机器、down表示当前的server暂时不参与负载均衡。</p>
<p>&nbsp;</p>
<p style="white-space: normal;">3.配置WEB服务器组</p>
<p style="white-space: normal;">在Web服务器192.168.1.123中的网站目录下编写index.html，内容如下：</p>
<p style="white-space: normal;">192.168.1.123</p>
<p style="white-space: normal;">在Web服务器192.168.1.91中的网站目录下编写index.html，内容如下：</p>
<p style="white-space: normal;">192.168.1.91</p>
<p style="white-space: normal;">4.测试验证</p>
<p style="white-space: normal;">重启负载均衡服务器配置后，在其他机器上多次访问192.168.1.141输出以下类似结果说明配置成功：</p>
<pre class="brush:bash;toolbar:false">curl 192.168.1.141
#输出192.168.1.123
curl 192.168.1.141
#输出192.168.1.91
curl 192.168.1.141
#输出192.168.1.91</pre>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/358.html">Nginx负载均衡配置——权重方式</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/358.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx负载均衡配置——轮询方式</title>
		<link>http://www.ywbk.cc/357.html</link>
		<comments>http://www.ywbk.cc/357.html#comments</comments>
		<pubDate>Thu, 23 Nov 2017 09:46:27 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[负载均衡]]></category>

		<guid isPermaLink="false">http://05bk.com/?p=357</guid>
		<description><![CDATA[负载均衡（load-balance）就是将负载分摊到多个操作单元上执行，从而提高服务的可用性和响应速度，带给用 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>负载均衡（load-balance）就是将负载分摊到多个操作单元上执行，从而提高服务的可用性和响应速度，带给用户更好的体验。Nginx不仅可以作为一个Web服务器或反向代理服务器，还可以通过upstream指令实现配置负载均衡服务器组实现多种方式的负载均衡。4种典型方式：<a href="http://05bk.com/357.html" target="_blank">轮询方式</a>、<a href="http://05bk.com/358.html" target="_blank">权重方式</a>、<a href="http://05bk.com/359.html" target="_blank">ip_hash方式</a>、<a href="http://05bk.com/360.html" target="_blank">第三方模块方式</a>。</p>
<p>轮询方式是默认方式，每个请求按照时间顺序逐一分配到不同的后端服务器进行处理，如有服务器宕机会被自动剔除。</p>
<p>&nbsp;</p>
<p>1.准备服务器</p>
<p>准备3台虚拟机，并全部安装Nginx服务器。可以参考：<a style="white-space: normal;" href="http://05bk.com/11.html" target="_blank">源码编译安装Nginx</a>，其中IP为192.168.1.141的服务器用作负载均衡服务器，另外两台用作后端Web服务器，IP分别为192.168.1.123和192.168.1.91</p>
<p>&nbsp;</p>
<p>2.配置负载均衡服务器nginx.conf</p>
<pre class="brush:bash;toolbar:false">＃配置域名为test.com的主机
server {
    listen       80;
    server_name  test.com;
    location / {
        proxy_pass http://web_server;
    }
}
＃配置负载均衡服务器组名称和地址
upstream web_server {
    server 192.168.1.123;
    server 192.168.1.91;
}</pre>
<p>在上述配置中，第6行用于指定代理的URL。第10～13行用于设置负载均衡服务器组，其中upstream指令后的web_server表示代理的服务器主机名，供第6行的proxy_pass指令执行反向代理时使用；第11～12行利用server指令在upstream块中配置了后端Web服务器，这些服务器可以有一个或多个，从而形成负载均衡服务器组。</p>
<p>&nbsp;</p>
<p>3.配置WEB服务器组</p>
<p>在Web服务器192.168.1.123中的网站目录下编写index.html，内容如下：</p>
<p>192.168.1.123</p>
<p style="white-space: normal;">在Web服务器192.168.1.91中的网站目录下编写index.html，内容如下：</p>
<p style="white-space: normal;">192.168.1.91</p>
<p>&nbsp;</p>
<p>4.测试验证</p>
<p>重启负载均衡服务器配置后，在其他机器上多次访问192.168.1.141输出以下类似结果说明配置成功：</p>
<pre class="brush:bash;toolbar:false">curl 192.168.1.141
#输出192.168.1.123
curl 192.168.1.141
#输出192.168.1.91</pre>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/357.html">Nginx负载均衡配置——轮询方式</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/357.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux配置Niginx+tomcat整合</title>
		<link>http://www.ywbk.cc/12.html</link>
		<comments>http://www.ywbk.cc/12.html#comments</comments>
		<pubDate>Sun, 19 Nov 2017 07:13:34 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://05bk.com/?p=12</guid>
		<description><![CDATA[首先已安装Niginx和tomcat可参考：Linux安装配置Niginx  Linux安装配置tomcat。 [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p>首先已安装Niginx和tomcat可参考：<a title="Linux安装配置Niginx" href="http://05bk.com/11.html" target="_blank">Linux安装配置Niginx</a>  <a title="Linux安装配置tomcat" href="http://www.05bk.com/352.html" target="_blank">Linux安装配置tomcat</a>。</p></blockquote>
<h2>1.修改Nginx配置文件</h2>
<pre class="prettyprint linenums">vim /usr/local/nginx/conf/nginx.conf
#在server｛｝中添加配置如下：
root    /var/wwwroot;#指定网页的根目录（可选）
location ~ .*.jsp$ { #定义所有以.jsp结尾
    index index.jsp; #默认网页为index.jsp
    proxy_pass http://localhost:8080;#代理地址为本机的8080端口
}</pre>
<h2>2.测试Nginx配置文件</h2>
<pre class="prettyprint linenums">/usr/local/nginx/sbin/nginx -t
#如下显示代表测试通过：
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful</pre>
<h2>3.重启并查看nginx端口</h2>
<pre class="prettyprint linenums">/usr/local/nginx/sbin/nginx -s reload
netstat -antp|grep nginx</pre>
<h2>4.验证</h2>
<p>在网站目录下放一个a.jsp，用浏览器访问http://localhost/a.jsp，应该可以看到正确的页面了。</p>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/12.html">Linux配置Niginx+tomcat整合</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/12.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx URL重写(rewrite)配置详解</title>
		<link>http://www.ywbk.cc/274.html</link>
		<comments>http://www.ywbk.cc/274.html#comments</comments>
		<pubDate>Tue, 14 Nov 2017 08:18:36 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://05bk.com/?p=274</guid>
		<description><![CDATA[和apache等web服务软件一样，rewrite的主要功能是实现RUL地址的重定向。Nginx的rewrit [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p>和apache等web服务软件一样，rewrite的主要功能是实现RUL地址的重定向。Nginx的rewrite功能需要PCRE软件的支持，即通过perl兼容正则表达式语句进行规则匹配的。默认参数编译nginx就会支持rewrite的模块，但是也必须要有PCRE的支持，也就是说系统已经安装了pcre-devel库。</p></blockquote>
<h2>1.rewrite语法格式及参数</h2>
<p>rewrite是实现URL重写的关键指令，根据regex（正则表达式）部分内容，重定向到replacement，结尾是flag标记。rewrite可用的标签段位置有：server,location,if。语法和参数说明如下：</p>
<pre class="prettyprint linenums">rewrite    &lt;regex&gt;    &lt;replacement&gt;    [flag];
rewrite是关键字：关键字不能改变
&lt;regex&gt;是正则：perl兼容正则表达式语句进行规则匹配
&lt;replacement&gt;是要替代的内容：将正则匹配的内容替换成replacement
[flag]是标记：rewrite支持的flag标记有：
last  #本条规则匹配完成后，继续向下匹配新的location URI规则
break  #本条规则匹配完成即终止，不再匹配后面的任何规则
redirect  #返回302临时重定向，浏览器地址会显示跳转后的URL地址
permanent  #返回301永久重定向，浏览器地址栏会显示跳转后的URL地址</pre>
<h2>2.rewrite举例</h2>
<pre class="prettyprint linenums">rewrite ^/(.*) http://www.czlun.com/$1 permanent;
#rewrite为固定关键字，表示开始进行rewrite匹配规则
#regex部分是 ^/(.*) ，这是一个正则表达式，表示匹配完整的域名和后面的路径地址
#replacement部分是http://www.czlun.com/$1，$1是取自regex部分()里的内容。匹配成功后跳转到的URL。
#flag部分 permanent表示永久301重定向标记，即跳转到新的 http://www.czlun.com/$1 地址上</pre>
<h2>3.regex常用正则表达式说明</h2>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#808080">字符</td>
<td style="color: #ffffff;" valign="top" bgcolor="#808080">描述</td>
</tr>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#1abc9c">\</td>
<td style="color: #ffffff;" valign="top" bgcolor="#f78585">将后面接着的字符标记为一个特殊字符或一个原义字符或一个向后引用。如“\n”匹配一个换行符，而“\$”则匹配“$”</td>
</tr>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#1abc9c">^</td>
<td style="color: #ffffff;" valign="top" bgcolor="#f78585">匹配输入字符串的起始位置</td>
</tr>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#1abc9c">$</td>
<td style="color: #ffffff;" valign="top" bgcolor="#f78585">匹配输入字符串的结束位置</td>
</tr>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#1abc9c">*</td>
<td style="color: #ffffff;" valign="top" bgcolor="#f78585">匹配前面的字符零次或多次。如“ol*”能匹配“o”及“ol”、“oll”</td>
</tr>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#1abc9c">+</td>
<td style="color: #ffffff;" valign="top" bgcolor="#f78585">匹配前面的字符一次或多次。如“ol+”能匹配“ol”及“oll”、“oll”，但不能匹配“o”</td>
</tr>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#1abc9c">?</td>
<td style="color: #ffffff;" valign="top" bgcolor="#f78585">匹配前面的字符零次或一次，例如“do(es)?”能匹配“do”或者“does”，&#8221;?&#8221;等效于&#8221;{0,1}&#8221;</td>
</tr>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#1abc9c">.</td>
<td style="color: #ffffff;" valign="top" bgcolor="#f78585">匹配除“\n”之外的任何单个字符，若要匹配包括“\n”在内的任意字符，请使用诸如“[.\n]”之类的模式。</td>
</tr>
<tr>
<td style="color: #ffffff;" valign="top" bgcolor="#1abc9c">(pattern)</td>
<td style="color: #ffffff;" valign="top" bgcolor="#f78585">匹配括号内pattern并可以在后面获取对应的匹配，常用$0&#8230;$9属性获取小括号中的匹配内容，要匹配圆括号字符需要\(Content\)</td>
</tr>
</tbody>
</table>
<h2>4.rewrite企业应用场景</h2>
<ul>
<li>可以调整用户浏览的URL，看起来更规范，合乎开发及产品人员的需求。</li>
<li>为了让搜索引擎搜录网站内容及用户体验更好，企业会将动态URL地址伪装成静态地址提供服务。</li>
<li>网址换新域名后，让旧的访问跳转到新的域名上。例如，访问京东的360buy.com会跳转到jd.com</li>
<li>根据特殊变量、目录、客户端的信息进行URL调整等</li>
</ul>
<h2>5.Nginx配置rewrite</h2>
<h3>（1）创建rewrite语句</h3>
<pre class="prettyprint linenums">vim /usr/local/nginx/conf/nginx.conf
#编辑虚拟主机配置文件文件内容
server {
        listen 80;
        server_name abc.com;
        rewrite ^/(.*) http://www.abc.com/$1 permanent;
}
#或者使用if
server {
        listen 80;
        server_name abc.com www.abc.com;
        if ( $host != 'www.abc.com'  ) {
                rewrite ^/(.*) http://www.abc.com/$1 permanent;
        }
}</pre>
<h3>（2）重启nginx服务</h3>
<pre class="prettyprint linenums">#重启之前测试下配置是个好习惯
/usr/local/nginx/sbin/nginx -t
#结果显示ok和success没问题便可重启
/usr/local/nginx/sbin/nginx -s reload</pre>
<h3>（3）查看跳转效果</h3>
<p>打开浏览器访问abc.com，页面打开后，URL地址栏的abc.com变成了www.abc.com说明URL重写成功。</p>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/274.html">Nginx URL重写(rewrite)配置详解</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/274.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx配置文件nginx.conf详解</title>
		<link>http://www.ywbk.cc/270.html</link>
		<comments>http://www.ywbk.cc/270.html#comments</comments>
		<pubDate>Wed, 08 Nov 2017 05:51:02 +0000</pubDate>
		<dc:creator><![CDATA[sxdgy]]></dc:creator>
				<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://05bk.com/?p=270</guid>
		<description><![CDATA[#【全局块】配置影响nginx全局的指令。 #定义Nginx运行的用户和用户组 #user nobody; # [&#8230;]]]></description>
				<content:encoded><![CDATA[<pre class="prettyprint linenums">#【全局块】配置影响nginx全局的指令。
#定义Nginx运行的用户和用户组
#user  nobody;
#nginx进程数，建议设置为等于CPU总核心数。
worker_processes  1;
#全局错误日志路径及级别，级别由低到高是：debug、info、notice、warn、error、crit
#error_log  logs/error.log  info;
#记录进程pid的文件
#pid        logs/nginx.pid;
#进程可打开的最大描述符数目，理论值是最多打开文件数(ulimit -n)与nginx进程数相除，但nginx分配请求不均匀，所以最好与ulimit -n 的值保持一致
#worker_rlimit_nofile 1024;
#【events块】配置影响nginx服务器或与用户的网络连接
events {
    #指定参考事件模型，可选：select(标准事件模型)、poll(标准事件模型)、kqueue(FreeBSD的高效事件模型)、epoll(Linux2.6+的高效事件模型)、/dev/poll(Solaris的高效事件模型)、Eventport(Solaris的高效事件模型)
    use epoll;
    #单个进程最大连接数，根据硬件调整，和前面工作进程配合起来用，尽量大
    worker_connections  1024;
    #保持活动超时时间
    keepalive_timeout 60;
    #客户端请求头部的缓冲区大小，必须设置为“系统分页大小(getconf PAGESIZE)”的整倍数。
    client_header_buffer_size 4k;
    #打开文件缓存数量，建议和上述“最大连接数”一致，inactive指经过多长时间文件没被请求后删除缓存。
    open_file_cache max=1024 inactive=60s;
    #多长时间检查一次缓存的有效性，默认是60s。
    open_file_cache_valid 80s;
    #缓存文件在指定时间内的最少使用次数，如果超过这个数字，文件描述符保留缓存中，否则将被移除。
    open_file_cache_min_uses 1;
    #当搜索一个文件时是否缓存错误信息，默认值off
    open_file_cache_errors on;
}
【http块】可以嵌套多个server，配置代理、缓存、日志等绝大多数功能和第三方模块的配置
#设定http服务器，利用它的反向代理功能提供负载均衡支持
http {
    #载入文件扩展名与文件类型映射表
    include       mime.types;
    #默认文件类型
    default_type  application/octet-stream;
    #默认编码
    #charset utf-8;
    #服务器名字的hash表最大值
    server_names_hash_max_size 512;
    #服务器名字的hash表大小
    server_names_hash_bucket_size 128;
    #如果Nginx检查语法提示需增大server_names_hash_max_size或server_names_hash_bucket_size，那么首要增大hash_max_size
    #客户端请求头部的缓冲区大小。可根据“系统分页大小(getconf PAGESIZE)”来设置
    client_header_buffer_size 4k;
    #大型客户端请求头缓冲区的数量和大小，优先使用client_header_buffer_size值，不够时才使用该值
    large_client_header_buffers 4 64k;
    #设定通过nginx上传文件的大小
    client_max_body_size 8m;
    #访问日志格式设定
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
        #日志格式用到的相关变量含义：
        #$remote_addr与$http_x_forwarded_for用以记录客户端的ip地址(通常web服务器放在反向代理的后面时通过$remote_add拿到的IP地址是反向代理的iP地址。可以用$http_x_forwarded_for记录客户端的IP地址和客户端请求的服务器地址。)
        #$remote_user：用来记录客户端用户名称；
        #$time_local：用来记录访问时间与时区；
        #$request：用来记录请求的url与http协议；
        #$status：用来记录请求状态；成功是200，
        #$body_bytes_sent：记录发送给客户端文件主体内容大小；
        #$http_referer：用来记录从那个页面链接访问过来的；
        #$http_user_agent：记录客户浏览器的相关信息；
    #定义http服务器的访问日志路径和使用哪个格式    
    #access_log  logs/access.log  main;
    #开启高效文件传输模式，普通应用设为on，磁盘IO重负载应用(如下载)，设为off。
    sendfile on;
    #开启目录列表访问，合适下载服务器，默认关闭。
    autoindex on;
    #开启nginx使用socke的TCP_CORK功能，此选项仅在使用sendfile的时候使用
    #tcp_nopush on;
    #开启nginx使用TCP_NODELAY功能
    #tcp_nodelay on;
    #长连接超时时间，单位是秒
    keepalive_timeout  65;
    #FastCGI相关参数是为了改善网站的性能：减少资源占用，提高访问速度
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    gzip on; #开启gzip压缩输出
    gzip_min_length 1k; #最小压缩文件大小
    gzip_buffers 4 16k;  #压缩缓冲区大小
    gzip_http_version 1.0; #压缩版本[1.0|1.1]
    gzip_comp_level 2; #压缩等级，范围1-9，越大压缩率越高
    gzip_types text/plain application/x-javascript text/css application/xml; #要压缩的MIME类型， #默认就已经包含text/html，就不用再写了，写上去会有一个warn。
    gzip_vary on; #和http头有关系，加个vary头，给代理服务器用的
    #开启限制IP连接数的时候需要使用
    #limit_zone crawler $binary_remote_addr 10m;
    #负载均衡配置
    upstream shili.com {
        #负载均衡分内置策略和扩展策略，再细分如下
        #1、轮询(内置默认)
        #每个请求按时间顺序逐一分配到不同的后端服务器，如果后端服务器down掉，能自动剔除
        server 192.168.80.121:80
        server 192.168.80.122:80
        #2、weight权重(内置)，根据机器配置定义,越大被分配到的几率越大
        #server 192.168.80.121:80 weight=3;
        #server 192.168.80.122:80 weight=2;
        #3、ip_hash按来访ip的hash(内置)，这样每个访客固定同一台后端服务器，可解决session问题
        #ip_hash;
        #server 192.168.0.14:88;
        #server 192.168.0.15:80;
        #4、fair按后端服务器的响应时间(扩展)，响应时间短的优先分配
        #server server1;
        #server server2;
        #fair;
        #5、url_hash按访问url的hash(扩展)，使每个url定向到同一个后端服务器，后端服务器为缓存时比较有效。
        #server squid1:3128;
        #server squid2:3128;
        #hash $request_uri;
        #hash_method crc32;
        #另外每个设备的状态可设置为:
        #1.down：表示单前的server暂时不参与负载
        #2.weight：为weight越大，负载的权重就越大。
        #3.max_fails：允许请求失败的次数默认为1.当超过最大次数时，返回proxy_next_upstream模块定义的错误
        #4.fail_timeout:max_fails次失败后，暂停的时间。
        #5.backup：其它所有的非backup机器down或者忙的时候，请求backup机器。所以这台机器压力会最轻。
        #nginx支持同时设置多组的负载均衡，用来给不用的server来使用。
        #client_body_in_file_only设置为On 可以讲client post过来的数据记录到文件中用来做debug
        #client_body_temp_path设置记录文件的目录 可以设置最多3层目录
        #location对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡
    }
    #【server块】配置虚拟主机
    server {
        listen  80; #监听端口
        server_name  localhost; #域名有多个时用空格隔开
        #charset utf-8; #设置字符集
        #keepalive_requests 120; #单连接请求上限次数
        #定义本虚拟主机的访问日志路径和使用哪个格式
        #access_log  logs/host.access.log  main;
        #【location块】配置路由、各种页面处理情况
        location / {
            root   html; #根目录
            index  index.html index.htm; #设置默认页
            deny 127.0.0.1;  #拒绝的ip
            allow 172.18.5.54; #允许的ip   
        }
        #将服务器404错误页面重定向到静态页面/404.html
        #error_page  404  /404.html;
        #将服务器错误页面重定向到静态页面/50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        #将PHP脚本反向代理到127.0.0.1:80
        location ~ \.php$ {
            proxy_pass   http://127.0.0.1; #代理转向服务器地址
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #以下是一些反向代理的配置，可选。
            proxy_set_header Host $host;
            #允许客户端请求的最大单文件字节数
            client_max_body_size 10m;
            #缓冲用户端请求的最大字节数
            client_body_buffer_size 128k;
            #表示使nginx阻止HTTP应答代码为400或者更高的应答。
            proxy_intercept_errors on;
            #代理连接后端超时时间
            proxy_connect_timeout 90;
            #代理发送数据给后端超时时间
            proxy_send_timeout 90;
            #代理读取后端服务器数据超时时间
            proxy_read_timeout 90;
            #设置代理服务器保存用户头信息的缓冲区大小
            proxy_buffer_size 4k;
            #设置用于读取应答的缓冲区数目和大小
            proxy_buffers 4 32k;
            #高负荷下缓冲大小（proxy_buffers*2）
            proxy_busy_buffers_size 64k;
            #设置在写入代理临时文件时数据的大小
            proxy_temp_file_write_size 64k;
        #}
        #将PHP脚本传递给在127.0.0.1:9000上监听的FastCGI服务器
        #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;
        #}
        #所有jsp的页面均交由tomcat或resin处理
        location ~ .(jsp|jspx|do)?$ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8080;
        }
        #设置静态文件缓存时间
        location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
        {
            expires 15d; 
        }
        #拒绝访问.htaccess文件
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    #基于IP、域名、端口的虚拟主机配置
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS服务器配置
    #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;
    #    }
    #}
}</pre>
<p>转载请注明：<a href="http://www.ywbk.cc">运维博客</a> &raquo; <a href="http://www.ywbk.cc/270.html">Nginx配置文件nginx.conf详解</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ywbk.cc/270.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
