官方测试Nginx能够支撑5万并发连接,实际生产环境中可以支撑2~4万并发连接数。 原因,主要是Nginx使用了最新的epoll(Linux2.6内核)和kqueue(freeBSD)网路I/O模型,而Apache使用的是传统的Select模型,其比较稳定的Prefork模式为多进程模式,需要经常派生子进程,所以消耗的CPU等服务器资源,要比Nginx高很多。 Nginx+PHP(FastCGI)服务器,在3万并发连接下,开启10个Nginx进程消耗150MB内存,15MB*10=150MB,开启的64个PHP-CGI进程消耗1280内存,20MB*64=1280MB,加上系统自身消耗的内存,总共消耗不到2GB的内存。 如果服务器的内存比较小,完全可以只开启25个PHP-CGI进程,这样PHP-CGI消耗的总内存数才500MB。购买F5BIG-IP、NetScaler等硬件负载均衡交换机,需要十多万到几十万人民币,而Nginx为开源软件,采用的是2-clause BSD-like协议,可以免费试用,并且可用于商业用途。 BSD开源协议是一个给使用者很大自由的协议,协议指出可以自由使用、修改源代码、也可以将修改后的代码作为开源或专用软件再发布。 网络和程序一样通俗易懂,即使,非专用系统管理员也能看懂。能够根据域名、URL的不同,将http请求分到不同的后端服务器群组。如果NginxProxy后端的某台Web服务器宕机了,不会影响前端的访问。支持GZIP压缩,可以添加浏览器本地缓存的Header头。用于反向代理,宕机的概率微乎其微。Nginx支持热部署,它的自动特别容易,并且,几乎可以7天*24小时不间断的运行,即使,运行数个月也不需要重新启动,还能够在不间断服务的情况下,对软件版本进行升级。 可以看出,Nginx在反向代理、Rewrite规则、稳定性、静态文件处理,内存消耗等方面,有很强的优势,使用Nginx取代传统的Apache服务器,会得到多方面的性能提升。
推荐步骤:1、在Cento01上安装nginx,设置网站根目录/www使用域名www.huyan.com访问,Centos02上安装DNS服务解析www.huyan.com和www.huyan.cn以及www.huyan.com.en域名2、配置网站跳转使用if和set判断,判断用户输入域名http://www.huyan.com/cn跳转到http://www.huyan.com.cn,判断用户输入域名http://www.huyan.com/en跳转到英文网站http://www.huyan.com.en3、return当用户输入http://www.huyan.com.cn给用户提示404错误,通过return实现当用户输入http://www.huyan.com.cn跳转到指定域名www.huyan.com的网站,匹配后通过break跳出终止地址重写4、永久重定向应用,当用户输入域名www.huyan.cn跳转到www.huyan.com网站,临时重定向应用,当用户输入域名www.huyan.com.en跳转到www.huyan.com网站,laset的应用当用户输入访问http://www.huyan.com/cn返回中文,客户端IP地址是192.168.100.30提示访问页面,不是192.168.100.30访问报错实验步骤:
2)挂载系统光盘配置本地 yum 仓库[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@centos01 ~]# ls /etc/yum.repos.d/
local.repo
[root@centos01 ~]# cat /etc/yum.repos.d/local.repo
[local]
name=centos7
baseurl=file:///mnt
enabled=1
gpgcheck=0[root@centos01 ~]# yum -y install pcre-devel zlib-devel[root@centos01 ~]# useradd -M -s /sbin/nologin nginx
2)解压配置安装 Nginxroot@centos01 ~]# rz
z waiting to receive.**B0100000023be50
[root@centos01 ~]# tar zxf ./nginx-1.16.1.tar.gz -C /usr/src/
[root@centos01 ~]# cd /usr/src/nginx-1.16.1/
[root@centos01 nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module[root@centos01 nginx-1.16.1]# make && make install[root@centos01 nginx-1.16.1]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@centos01 nginx-1.16.1]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] getpwnam("nginx") failed
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed[root@centos01 ~]# mkdir /www
mkdir: 无法创建目录"/www": 文件已存在
[root@centos01 ~]# echo "www.huyan.com" > /www/index.html[root@centos01 ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes 1;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.huyan.com;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
root /www;
index index.html index.htm;
}
}
}
3)启动 Nginx 服务监听端口号[root@centos01 ~]# nginx
[root@centos01 ~]# netstat -anptu | grep nginx
tcp 0 0 192.168.100.10:80 0.0.0.0:* LISTEN 4171/nginx: master
2)挂载系统关盘安装 DNS 服务[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@centos02 ~]# rpm -ivh /mnt/Packages/bind-9.9.4-50.el7.x86_64.rpm
警告:/mnt/Packages/bind-9.9.4-50.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:bind-32:9.9.4-50.el7 ################################# [100%]
[root@centos02 ~]# rpm -ivh /mnt/Packages/bind-chroot-9.9.4-50.el7.x86_64.rpm
警告:/mnt/Packages/bind-chroot-9.9.4-50.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:bind-chroot-32:9.9.4-50.el7 ################################# [100%][root@centos02 ~]# vim /etc/named.conf
options {
listen-on port 53 { 192.168.100.20; };
directory "/var/named/";
};
zone "huyan.com" IN {
options {
listen-on port 53 { 192.168.100.20; };
directory "/var/named/";
};
zone "huyan.com" IN {
type master;
file "/var/named/huyan.com.zone";
};
zone "huyan.com.cn" IN {
type master;
file "/var/named/huyan.com.cn.zone";
};
zone "huyan.com.en" IN {
type master;
file "/var/named/huyan.com.en.zone";
};
[root@centos02 ~]# named-checkconf /etc/named.conf[root@centos02 ~]# vim /var/named/huyan.com.zone
$TTL 86400
@ SOA huyan.com. root.huyan.com.(
2023021210
1H
15M
1W
1D
)
@ NS centos02.huyan.com.
centos02 A 192.168.100.20
www A 192.168.100.10
[root@centos02 ~]# named-checkzone huyan.com /var/named/huyan.com.zone
zone huyan.com/IN: loaded serial 2023021210
OK
[root@centos02 ~]# vim /var/named/huyan.com.cn.zone
$TTL 86400
@ SOA huyan.com.cn. root.huyan.com.cn.(
2023021210
1H
15M
1W
1D
)
@ NS centos02.huyan.com.cn.
centos02 A 192.168.100.20
www A 192.168.100.10
[root@centos02 ~]# named-checkzone huyan.com.cn /var/named/huyan.com.cn.zone
zone huyan.com.cn/IN: loaded serial 2023021210
OK
[root@centos02 ~]# vim /var/named/huyan.com.en.zone
$TTL 86400
@ SOA huyan.com.en. root.huyan.com.en.(
2023021210
1H
15M
1W
1D
)
@ NS centos02.huyan.com.en.
centos02 A 192.168.100.20
www A 192.168.100.10
[root@centos02 ~]# named-checkzone huyan.com.en /var/named/huyan.com.en.zone
zone huyan.com.en/IN: loaded serial 2023021210
OK[root@centos02 ~]# systemctl start named
[root@centos02 ~]# systemctl enable named
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
7)客户端访问
[root@centos01 ~]# mkdir /www/cn
[root@centos01 ~]# echo "cn" > /www/cn/index.html[root@centos01 ~]# mkdir /www/en
[root@centos01 ~]# echo "en" > /www/en/index.html[root@centos01 ~]# ls -R /www/
/www/:
cn en error index.html
/www/cn:
index.html
/www/en:
index.html
/www/error:
error.html[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes 1;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 192.168.100.10:80;
server_name www.huyan.com;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
root /www;
index index.html index.htm;
}
}
server {
listen 192.168.100.10:80;
server_name www.huyan.com.cn;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
set $language 'cn';
rewrite ^/$ http://www.huyan.com/$language;
}
}
server {
listen 192.168.100.10:80;
server_name www.huyan.com.en;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
set $language 'en';
rewrite ^/$ http://www.huyan.com/$language;
}
}
}[root@centos01 ~]# killall nginx
[root@centos01 ~]# killall nginx
nginx: no process found
[root@centos01 ~]# nginx
[root@centos01 ~]# netstat -anptu | grep nginx
tcp 0 0 192.168.100.10:80 0.0.0.0:* LISTEN 4993/nginx: master
2)客户端访问英文网站
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
22 server {
23 listen 192.168.100.10:80;
24 server_name www.huyan.com.cn;
25 charset utf-8;
26 access_log logs/www.huyan.com.access.log;
27 location / {
28 if ($http_host ~ (cn)$) {
29 set $language 'cn';
30 rewrite ^/$ http://www.huyan.com/$language;
31 }
32 if ($http_host ~ (cn)$) {
33 set $language 'cn';
34 rewrite ^/$ http://www.huyan.com/$language;
35 }
36 }
37 }
38 server {
39 listen 192.168.100.10:80;
40 server_name www.huyan.com.en;
41 charset utf-8;
42 access_log logs/www.huyan.com.access.log;
43 location / {
44 set $language 'en';
45 rewrite ^/$ http://www.huyan.com/$language;
46 }
47 }
48 }
2)重启 Nginx 服务[root@centos01 ~]# killall nginx
[root@centos01 ~]# killall nginx
nginx: no process found
[root@centos01 ~]# nginx
[root@centos01 ~]# netstat -anptu | grep nginx
tcp 0 0 192.168.100.10:80 0.0.0.0:* LISTEN 5127/nginx: master
4)访问英文网站
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:80;
server_name www.huyan.com.cn;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
if ($http_host = "www.huyan.com.cn") {
return 404;
}
}
[root@centos01 ~]# 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[root@centos01 ~]# killall nginx
[root@centos01 ~]# killall nginx
nginx: no process found
[root@centos01 ~]# nginx
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:80;
server_name www.huyan.com.en;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
if ($http_host = "www.huyan.com.en") {
rewrite ^/$ http://www.huyan.com;
}
}
[root@centos01 ~]# 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[root@centos01 ~]# killall nginx
[root@centos01 ~]# killall nginx
nginx: no process found
[root@centos01 ~]# nginx
[root@centos01 ~]# netstat -anptu | grep nginx
tcp 0 0 192.168.100.10:80 0.0.0.0:* LISTEN 5246/nginx: master

[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:80;
server_name www.huyan.com.en;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
if ($http_host = "www.huyan.com.en") {
break;
rewrite ^/$ http://www.huyan.com;
}
}
[root@centos01 ~]# 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[root@centos01 ~]# killall nginx
[root@centos01 ~]# killall nginx
nginx: no process found
[root@centos01 ~]# nginx
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:80;
server_name www.huyan.com.cn;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
rewrite ^/$ http://www.huyan.com permanent;
}
}
[root@centos01 ~]# 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[root@centos01 ~]# killall nginx
[root@centos01 ~]# killall nginx
nginx: no process found
[root@centos01 ~]# nginx

[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:80;
server_name www.huyan.com.en;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
rewrite ^/$ http://www.huyan.com redirect;
}
}
[root@centos01 ~]# 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[root@centos01 ~]# killall nginx
[root@centos01 ~]# killall nginx
nginx: no process found
[root@centos01 ~]# nginx

[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.bdqn.com.cn;
charset utf-8;
access_log logs/www.bdqn.com.access.log;
location / {
if ($http_host ~* (cn)$){
rewrite ^/$ http://www.bdqn.com last;
}
}
}
server {
listen 192.168.100.10:80;
server_name www.huyan.com.en;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location /en {
root /www/en/;
index index.html index.htm;
}
}
}
[root@centos01 ~]# 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[root@centos01 ~]# killall nginx
[root@centos01 ~]# killall nginx
nginx: no process found
[root@centos01 ~]# nginx

[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 192.168.100.10:80;
server_name www.huyan.com;
charset utf-8;
access_log logs/www.huyan.com.access.log;
location / {
root /www;
index index.html index.htm;
set $rewrite true;
if ($remote_addr = "192.168.100.30") {
set $rewrite fales;
}
if ($rewrite = true) {
rewrite (.+) /error.html;
}
location = /error.html {
root /www/error/;
}
}
}
}
[root@centos01 ~]# 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
4)是 192.168.100.30 访问显示主页
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge
只是想确保我理解了事情。据我目前收集到的信息,Cucumber只是一个“包装器”,或者是一种通过将事物分类为功能和步骤来组织测试的好方法,其中实际的单元测试处于步骤阶段。它允许您根据事物的工作方式组织您的测试。对吗? 最佳答案 有点。它是一种组织测试的方式,但不仅如此。它的行为就像最初的Rails集成测试一样,但更易于使用。这里最大的好处是您的session在整个Scenario中保持透明。关于Cucumber的另一件事是您(应该)从使用您的代码的浏览器或客户端的角度进行测试。如果您愿意,您可以使用步骤来构建对象和设置状态,但通常您
A/ctohttp://wiki.nginx.org/CoreModule#usermaster进程曾经以root用户运行,是否可以以不同的用户运行nginxmaster进程? 最佳答案 只需以非root身份运行init脚本(即/etc/init.d/nginxstart),就可以用不同的用户运行nginxmaster进程。如果这真的是你想要做的,你将需要确保日志和pid目录(通常是/var/log/nginx&/var/run/nginx.pid)对该用户是可写的,并且您所有的listen调用都是针对大于1024的端口(因为绑定(
在Rails自动生成的功能测试(test/functional/products_controller_test.rb)中,我看到以下代码:classProductsControllerTest我的问题是:方法调用products()在哪里/如何定义?products(:one)到底是什么意思?看代码,大概意思是“创建一个产品”,但是它是如何工作的呢?注意我是Ruby/Rails的新手,如果这些是微不足道的问题,我深表歉意。 最佳答案 如果您查看test/fixtures文件夹,您会看到一个products.yml文件。这是在您创建
我想验证一个电子邮件地址是否是PayPal用户。是否有API调用来执行此操作?是否有执行此操作的ruby库?谢谢 最佳答案 GetVerifiedStatus来自PayPal'sAdaptiveAccounts平台会为您做这件事。PayPal没有任何codesamples或SDKs用于Ruby中的自适应帐户,但我确实找到了编写codeforGetVerifiedStatusinRuby的人.您需要更改该代码以检查他们拥有的帐户类型的唯一更改是更改if@xml['accountStatus']!=nilaccount_status
在我的一些Controller中,我有一个before_filter检查用户是否登录?用于CRUD操作。application.rbdeflogged_in?unlesscurrent_userredirect_toroot_pathendendprivatedefcurrent_user_sessionreturn@current_user_sessionifdefined?(@current_user_session)@current_user_session=UserSession.findenddefcurrent_userreturn@current_userifdefine
require'pp'p*1..10这会打印出1-10。为什么这么简洁?您还可以用它做什么? 最佳答案 它是“splat”运算符。它可用于分解数组和范围并在赋值期间收集值。这里收集赋值中的值:a,*b=1,2,3,4=>a=1b=[2,3,4]在此示例中,内部数组([3,4])中的值被分解并收集到包含数组中:a=[1,2,*[3,4]]=>a=[1,2,3,4]您可以定义将参数收集到数组中的函数:deffoo(*args)pargsendfoo(1,2,"three",4)=>[1,2,"three",4]
对于我的大部分应用程序,我从Geocoder获取城镇/城市的纬度、经度、邮政编码等。我只是投入城市和州,作为返回,我得到了我处于一个有field的场景中。该场所需要一个地址,我正在从另一个来源获取该场所的纬度和经度。使用Geocodergem,我可以通过给地址提供经纬度来获取地址吗? 最佳答案 在Rails控制台中运行。latitude=40.0397longitude=-76.30144geo_localization="#{latitude},#{longitude}"query=Geocoder.search(geo_loca
我读过的关于Ruby符号的每一篇文章都在谈论符号相对于字符串的效率。但是,这不是1970年代。我的电脑可以处理一些额外的垃圾收集。我错了吗?我拥有最新最好的奔腾双核处理器和4GBRAM。我认为这应该足以处理一些字符串。 最佳答案 您的计算机可能能够处理“一点点额外的垃圾收集”,但是当“一点点”发生在运行数百万次的内部循环中时呢?如果它在内存有限的嵌入式系统上运行呢?有很多地方你可以随意使用字符串,但在某些地方你不能。这完全取决于上下文。 关于ruby-现代计算机的功能是否不足以处理字符串