﻿<?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://help.vps12.com/tag/nginx/feed" rel="self" type="application/rss+xml" />
	<link>https://help.vps12.com</link>
	<description>分享服务器运维及实践解决方案</description>
	<lastBuildDate>Sat, 25 Jan 2025 07:14:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>宝塔等Nginx环境添加允许跨域Header头问题补充</title>
		<link>https://help.vps12.com/1998.html</link>
		<comments>https://help.vps12.com/1998.html#comments</comments>
		<pubDate>Fri, 01 May 2020 19:41:43 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[网络产品]]></category>
		<category><![CDATA[解决方案]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[vps12.com]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1998</guid>
		<description><![CDATA[宝塔等Nginx环境添加允许跨域Header头 我已宝塔面板为例: 点击站点修改 点击配置文件 在 39 行下面添加 add_header &#8216;Access-Control-Allow-Origin&#8217; &#8216;*&#8217;; add_header &#8216;Access-Control-Allow-Credentials&#8217; &#8216;true&#8217;; add_header &#8216;Access-Control-Allow-Methods&#8217; &#8216;GET, POST, OPTIONS&#8217;; 然后重启 nginx. 下面是通用 nginx 添加允许跨域header头 使用ngx_http_headers_module中的add_header指令，在响应头中添加允许跨域。 Syntax: add_header name value [always]; Default: — Context: http, server, location, if in location 一般地，我们把允许跨域的头加在动态接口后面，比如 php，就加在解析 php 后面 add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST; 注意，在实际中 Allow-Origin 不要指定为*，要设置为允许访问的域名，比如 http://abc.com]]></description>
		<wfw:commentRss>https://help.vps12.com/1998.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>宝塔面板安装好后，默认ip访问的那个html页面在哪个文件夹？</title>
		<link>https://help.vps12.com/1886.html</link>
		<comments>https://help.vps12.com/1886.html#comments</comments>
		<pubDate>Wed, 13 Feb 2019 13:27:56 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[网络产品]]></category>
		<category><![CDATA[解决方案]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1886</guid>
		<description><![CDATA[宝塔面板很好用。大家都知道不过有些默认的选择项目也给大家说一下。 宝塔面板ip地址默认访问页在此目录下(默认安装的是NMP环境就在如下路径中) /www/server/nginx/html/ 删除掉index.html或是改名不就可以不用出现访问ip地址时的尴尬了。因为别人一看就知道你是哪个面板了。]]></description>
		<wfw:commentRss>https://help.vps12.com/1886.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lvs,nginx,haproxy的优缺点及适合场景(转)</title>
		<link>https://help.vps12.com/1838.html</link>
		<comments>https://help.vps12.com/1838.html#comments</comments>
		<pubDate>Wed, 08 Aug 2018 12:34:05 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[网络产品]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1838</guid>
		<description><![CDATA[Nginx/LVS/HAProxy的基于Linux的开源免费的负载均衡软件。 LVS：使用集群技术和Linux操作系统实现一个高性能、高可用的服务器，它具有很好的可伸缩性、可靠性和可管理性，是一款强大实用的开源软件。 LVS的优点： 1：抗负载能力强、是工作在网络4层之上仅作分发之用，没有流量的产生，这个特点也决定了它在负载均衡软件里的性能最强的，也保证了均衡器I/O的性能不会受到大流量的影响。； 2：lvs是专门的负载均衡软件，对任何应用都可以做负载均衡； 3：工作稳定，因为其本身抗负载能力很强，自身有完整的双机热备方案，目前用的比较多的是lvs+keepalived，比较大型的用的多的是lvs+heartbeat。 nginx的优点： 1：Nginx的高并发，同时能承载上万个并发连接； 2：nginx有充足的第三方功能模块的支持，主要通过upstream模块进行负载均衡； 3：nginx对网络的依赖较小，理论上只要Ping得通，网页访问正常，nginx就能连得通； 4：工作在网络的7层之上，可以针对http应用做一些分流的策略，它的正则规则比haproxy更为强大和灵活，这也是它目前广泛流行的主要原因之一，nginx单凭这点可利用的场合就远多于lvs了。 nginx的缺点： 1：将Nginx当做反向代理时，负载均衡功能不是很好，对后端服务器的健康检查功能较弱； 2：nginx仅能支持http、https和email协议，这样就在适用范围上面小些，这个是它的缺点； 3：nginx只支持通过端口来检测，不支持通过url来检测。 haproxy的优点： 1：HAProxy的优点能够补充Nginx的一些缺点，比如支持Session的保持，Cookie的引导；同时支持通过获取指定的url来检测后端服务器的状态； 2：haproxy也是专门的负载均衡软件，Haproxy可以负载http，还可以负载均衡mysql； 3：HAProxy是支持虚拟主机的。 总结这么多，我觉得根据不同的需求，不同的功能，可以选择不同的软件类的负载均衡软件，当然也是可以选择硬件类的负载均衡器。 像对于大型的，需要进行高并发的网站或者对网络不太严格的时候，可以使用nginx； 对于大型的Web服务器的时候可以使用haproxy； 对性能有严格要求的时候可以使用lvs，就单纯从负载均衡的角度来说，lvs也许会成为主流，更适合现在大型的互联网公司。]]></description>
		<wfw:commentRss>https://help.vps12.com/1838.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx代理socket tcp/udp</title>
		<link>https://help.vps12.com/1829.html</link>
		<comments>https://help.vps12.com/1829.html#comments</comments>
		<pubDate>Fri, 06 Jul 2018 20:03:01 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[网络产品]]></category>
		<category><![CDATA[解决方案]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1829</guid>
		<description><![CDATA[准备一台linux服务器。nginx官网：http://nginx.org/ 。在网上搜到大致用的是 ngx_stream_core_module 这个模块，这里你也可以关注一下官方文档中的其他模块都是做什么的，那么这有相关的启用配置说明，与示例配置。 第一句便是：该ngx_stream_core_module模块是自1.9.0版本。此模块不是默认构建的，应使用配置参数启用 &#8211;with-stream 。 那好吧，我们就安装nginx，搞这个的，安装应该都会吧。 ?View Code BASH1 2 &#91;root@localhost /&#93;# cd /usr/local/src &#91;root@localhost src&#93;# wget http://nginx.org/download/nginx-1.11.10.tar.gz 然后解压，解压完，根据文档提示需要使用这个参数&#8211;with-stream 来启用功能。 ?View Code BASH1 &#91;root@localhost src&#93;# ./configure --prefix=/usr/local/nginx --with-stream 然后，make，make install。 完成之后就是nginx配置配置文件啦，这个文档中有示例，可知与events模块平级，按照这做就好啦。 ?View Code BASH1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [...]]]></description>
		<wfw:commentRss>https://help.vps12.com/1829.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx获取真实ip——toa模块(转)</title>
		<link>https://help.vps12.com/1827.html</link>
		<comments>https://help.vps12.com/1827.html#comments</comments>
		<pubDate>Fri, 06 Jul 2018 19:04:30 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[网络产品]]></category>
		<category><![CDATA[解决方案]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1827</guid>
		<description><![CDATA[toa模块是为了让后端的realserver能够看到真实的clientip而不是lvs的dip。 1、下载http://kb.linuxvirtualserver.org &#8230; 86_64.rs.src.tar.gz 2、解压 3、编辑.config，将CONFIG_IPV6=M改成CONFIG_IPV6=y 测试的时候发现如果不改会遇到报错，可以看下这个帖子：http://bbs.linuxtone.org/forum.p &#8230; 1631&#38;pid=111599 4、编辑Makefile，可以在EXTRAVERSION =处加上自定义的一些说明，将会在uname -r中显示。比如-shanks.e11.x86_64 5、make -jn 6、make modules_install 7、make install 8、修改/boot/grub/grub.conf     用第一个内核启动 9、reboot 10、装个nginx，试试看能不能看见真实的clientip。 参考：http://kb.linuxvirtualserver.org/wiki/IPVS_FULLNAT_and_SYNPROXY]]></description>
		<wfw:commentRss>https://help.vps12.com/1827.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx could not build the server_names_hash 错误的解决办法</title>
		<link>https://help.vps12.com/1739.html</link>
		<comments>https://help.vps12.com/1739.html#comments</comments>
		<pubDate>Mon, 03 Jul 2017 20:13:14 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[解决方案]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1739</guid>
		<description><![CDATA[在给nginx 配置了一个超长的域名后，通过 /usr/local/nginx/sbin/ngnix -t 检查配置文件时出现一下错误： . 代码如下: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 解决办法是在nginx的配置文件的http段中增加如下配置： . 代码如下: server_names_hash_bucket_size 64; 如果已经存在，需要加大后面的数值，注意：该数值是32的倍数为宜。 下面是nginx官方文档： . 代码如下: 如果定义了大量名字，或者定义了非常长的名字，那可能需要在http配置块中使用server_names_hash_max_size和server_names_hash_bucket_size指令进行调整。server_names_hash_bucket_size的默认值可能是32，或者是64，或者是其他值，取决于CPU的缓存行的长度。如果这个值是32，那么定义“too.long.server.name.example.org”作为虚拟主机名就会失败，而nginx显示下面错误信息： could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32 出现了这种情况，那就需要将指令的值扩大一倍： http { server_names_hash_bucket_size 64; &#8230; 如果定义了大量名字，得到了另外一个错误： could not build the server_names_hash, you should increase either server_names_hash_max_size: 512 [...]]]></description>
		<wfw:commentRss>https://help.vps12.com/1739.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何用DNS+GeoIP+Nginx+Varnish做世界级的CDN(转)</title>
		<link>https://help.vps12.com/1360.html</link>
		<comments>https://help.vps12.com/1360.html#comments</comments>
		<pubDate>Sat, 08 Aug 2015 18:43:52 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[解决方案]]></category>
		<category><![CDATA[软件使用]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[Varnish]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1360</guid>
		<description><![CDATA[如何用BIND, GeoIP, Nginx, Varnish来创建你自己的高效的CDN网络？ CDN，意思是Content Distrubtion Network，意思是内容分发网络，简单的说，就是全地域范围内的负载均衡，全地域的概念可以是全国，也可以是全世界。由统一的DNS服务器进行地址转发，选择离用户最近的地区服务器进行负载均衡。本质上是从一个机房内的负载均衡扩展到了全世界范围内的负载均衡。同时可以将本地化的内容，由当地的服务器实现。做浏览器的地区自动选择。 比如在中国，被人为划分成两大区域，北方是网通，南方是电信。这两个网络之间互访是比较慢的。作为大型网站，一种解决办法是将全部服务器架设在双线或三线ISP处，由ISP来提供路由上的选择。这样做，线路的成本会比较高。另一种办法就是将服务器架设在两边，南方一台，北方一台，然后由服务器自己选择，如果IP在电信，就转发请求到南方的服务器，如果是网通就转发到北方的服务器。 再扩大范围，可以将美国来的请求交由美国服务器处理，这样也缩短了用户在路由上的等待时间。这就是内容分发网络。 而作为这个网络上的所有节点，都可以当成虚拟服务器来看待。至于在各地的服务器如何做负载均衡，可以由各节点之间完成。 准备工作如下：你需要下载如下软件以实现上述功能 Nginx，BIND，GeoIP，Varnish 接下来是编译和安装bind9和geoip # tar -xzvf bind-9.2.4.tar.gz # tar -xzvf GeoIP-1.4.6.tar.gz # cd GeoIP-1.4.6 # ./configure –prefix=/usr/local/geoip # make # make install # cd .. # patch -p0 &#60; bind-9.2.4-geodns-patch/patch.diff //给bind9打补丁，让bind9直接支持geoip库 # cd bind-9.2.4 # CFLAGS=”-I/usr/local/geoip/include” LDFLAGS=”-L/usr/local/geoip/lib -lGeoIP” ./configure –prefix=/usr/local/bind # make # make install [...]]]></description>
		<wfw:commentRss>https://help.vps12.com/1360.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计（转）</title>
		<link>https://help.vps12.com/1355.html</link>
		<comments>https://help.vps12.com/1355.html#comments</comments>
		<pubDate>Tue, 04 Aug 2015 17:25:16 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[解决方案]]></category>
		<category><![CDATA[软件使用]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1355</guid>
		<description><![CDATA[架构简介 前几天网友来信说帮忙实现这样一个架构：只有两台机器，需要实现其中一台死机之后另一台能接管这台机器的服务，并且在两台机器正常服务时，两台机器都能用上。于是设计了如下的架构。 此架构主要是由keepalived实现双机高可用，维护了一个外网VIP,一个内网VIP。正常情况时，外网VIP和内网VIP都绑定在server1服务器，web请求发送到server1的nginx，nginx对于静态资源请求就直接在本机检索并返回，对于php的动态请求，则负载均衡到server1和server2。对于SQL请求，会将此类请求发送到Atlas MySQL中间件，Atlas接收到请求之后，把涉及写操作的请求发送到内网VIP，读请求操作发送到mysql从，这样就实现了读写分离。 当主服务器server1宕机时，keepalived检测到后，立即把外网VIP和内网VIP绑定到server2，并把server2的mysql切换成主库。此时由于外网VIP已经转移到了server2，web请求将发送给server2的nginx。nginx检测到server1宕机，不再把请求转发到server1的php-fpm。之后的sql请求照常发送给本地的atlas，atlas把写操作发送给内网VIP，读操作发送给mysql从，由于内网VIP已经绑定到server2了，server2的mysql同时接受写操作和读操作。 当主服务器server1恢复后，server1的mysql自动设置为从，与server2的mysql主同步。keepalived不抢占server2的VIP，继续正常服务。 架构要求 要实现此架构，需要三个条件： 1、服务器可以设置内网IP，并且设置的内网IP互通; 2、服务器可以随意绑定IDC分配给我们使用的外网IP，即外网IP没有绑定MAC地址; 3、MySQL服务器支持GTID，即MySQL-5.6.5以上版本。 环境说明 server1 eth0: 10.96.153.110(对外IP) eth1: 192.168.1.100(对内IP) server2 eth0: 10.96.153.114(对外IP) eth1: 192.168.1.101(对内IP) 系统都是CentOS-6。 对外VIP: 10.96.153.239 对内VIP: 192.168.1.150 hosts设置 /etc/hosts: 192.168.1.100 server1 192.168.1.101 server2 Nginx PHP MySQL Memcached安装 这几个软件的安装推荐使用EZHTTP来完成。 解决session共享问题 php默认的session存储是在/tmp目录下，现在我们是用两台服务器作php请求的负载，这样会造成session分布在两台服务器的/tmp目录下，导致依赖于session的功能不正常。我们可以使用memcached来解决此问题。 上一步我们已经安装好了memcached，现在只需要配置php.ini来使用memcached，配置如下，打开php.ini配置文件，修改为如下两行的值： session.save_handler = memcache session.save_path = “tcp://192.168.1.100:11211,tcp://192.168.1.101:11211&#8243; 之后重启php-fpm生效。 Nginx配置 Server1配置 http { [...] upstream php-server [...]]]></description>
		<wfw:commentRss>https://help.vps12.com/1355.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx 限速</title>
		<link>https://help.vps12.com/1345.html</link>
		<comments>https://help.vps12.com/1345.html#comments</comments>
		<pubDate>Tue, 04 Aug 2015 13:29:30 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[解决方案]]></category>
		<category><![CDATA[软件使用]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1345</guid>
		<description><![CDATA[注意： nginx 1.1.8 之后的版本的语法改为limit_conn_zone $binary_remote_addr zone=NAME:10m; NAME 就是 zone 的名字详情请看这里 http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html 限制连接数: 要限制连接，必须先有一个容器对连接进行计数，在http段加入如下代码： “zone=” 给它一个名字，可以随便叫，这个名字要跟下面的 limit_conn 一致 $binary_remote_addr = 用二进制来储存客户端的地址，1m 可以储存 32000 个并发会话 &#8230; 省掉 N 字 http { limit_conn_zone $binary_remote_addr zone=addr:10m; 接下来需要对server不同的位置（location段）进行限速，比如限制每个IP并发连接数为1，则 server { listen 80; server_name 192.168.11.128; index index.html index.htm index.php; limit_conn addr 1; #是限制每个IP只能发起1个连接 （addr 要跟 limit_conn_zone 的变量对应） limit_rate 100k; #限速为 100KB/秒 [...]]]></description>
		<wfw:commentRss>https://help.vps12.com/1345.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx配置limit_conn_zone来限制并发连接数以及下载带宽</title>
		<link>https://help.vps12.com/1343.html</link>
		<comments>https://help.vps12.com/1343.html#comments</comments>
		<pubDate>Tue, 04 Aug 2015 13:28:48 +0000</pubDate>
		<dc:creator>vps12.com</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[解决方案]]></category>
		<category><![CDATA[软件使用]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[vps12.com]]></category>

		<guid isPermaLink="false">http://help.vps12.com/?p=1343</guid>
		<description><![CDATA[配置方法如下： 1、在nginx.conf里的http{}里加上如下代码： #ip limit limit_conn_zone $binary_remote_addr zone=perip:10m; limit_conn_zone $server_name zone=perserver:10m; 2、在需要限制并发数和下载带宽的网站配置server{}里加上如下代码： limit_conn perip 2; limit_conn perserver 20; limit_rate 100k; 补充说明下参数： $binary_remote_addr是限制同一客户端ip地址； $server_name是限制同一server最大并发数； limit_conn为限制并发连接数； limit_rate为限制下载速度； 转另一篇文章：nginx 限速 注意： nginx 1.1.8 之后的版本的语法改为limit_conn_zone $binary_remote_addr zone=NAME:10m; NAME 就是 zone 的名字详情请看这里 http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html 限制连接数: 要限制连接，必须先有一个容器对连接进行计数，在http段加入如下代码： “zone=” 给它一个名字，可以随便叫，这个名字要跟下面的 limit_conn 一致 $binary_remote_addr = 用二进制来储存客户端的地址，1m 可以储存 32000 个并发会话 &#8230; 省掉 N 字 http { [...]]]></description>
		<wfw:commentRss>https://help.vps12.com/1343.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
