Articles of nginx

使用nginx进行负载平衡时,请求速度较慢

我已经将nginx设置为负载均衡器,将代理请求反向代理到2个Apache服务器。 我已经使用ab进行了基准testing,并且每秒获得约35个请求,并在两个后端服务器(不使用ip_hash)之间分配请求。 令我困惑的是,如果我通过ab直接查询后端服务器,那么每秒可以获得约50个请求。 我已经在ab中尝试了许多不同的值,其中最常见的是具有100个并发连接的1000个请求。 任何知道为什么stream量分布在2台服务器上的结果是每秒钟的请求数量比直接打到的要less? 附加信息: 我已经尝试了1到8之间的worker_processes值,1024到8092之间的worker_connections,并尝试了keepalive 0和65。 我的主要configuration目前看起来像这样: user www-data; worker_processes 1; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; worker_rlimit_nofile 8192; events { worker_connections 2048; use epoll; } http { include /etc/nginx/mime.types; sendfile on; keepalive_timeout 0; tcp_nodelay on; gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } 我有一个虚拟主机(在可用的站点中),通过本地networkingredirect到/ 2后端的所有内容。

如何configurationnginx + php(fcgi)与不同的用户运行每个子域?

我很新的nginx和 – 更多的学习目的 – 即时通讯尝试configurationNginx的运行与不同的用户为每个子域的PHP。 例如,我想使用用户john在foo.example.com上的所有脚本和在bar.example.com上的用户jack 。 我已经创build了我的系统上的用户(Ubuntu的服务器),但我不知道如何指示nginx使用用户 – 即时寻找一个解决scheme,可以处理easly许多用户,可以说〜2000年。 看文档,我不明白,如果我必须为每个用户(不同的端口)产生一个php5-cgi进程,然后把它们抓到我的sites-available网站(如我说我是一个新手,但这看起来像我一个服务器自杀),而在nginxconfiguration中只有2个页面是用中文( page1 , page2 )来写的,用google翻译很难翻译(但是,看代码,使用完全不同于server-suicide方式) 任何build议? 更新 galador的答案做的工作,但即时通讯设法build立一个dinamycal环境(与通配符子域名)不需要重新启动nginx / fpm每个新的网站,这可能吗?

用“–with-http_stub_status_module”configuration行重新编译NGINX

我用sudo apt-get install nginx安装了NGINX,现在我想用configuration选项–with-http_stub_status_module重新编译它。 我怎么能做到这一点,有没有办法让我的所有/etc/nginxconfiguration失去? 谢谢! 汤姆。

nginx proxypass重写基址

我试图设置Nginx使用proxy_pass转发请求到几个后端服务。 其中一些不支持在子文件夹下访问,所以我必须添加一个重写来剥离附加的子文件夹,以允许从同一端口访问它们。 有关改进重写的任何提示? curl输出; :~$ curl -I -k https://example.net/internal HTTP/1.1 404 Not Found Server: nginx/1.0.5 Date: Thu, 19 Jan 2012 22:30:46 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Content-Length: 145 :~$ curl -I -k https://example.net/internal/ HTTP/1.1 200 OK Server: nginx/1.0.5 Date: Thu, 19 Jan 2012 22:31:12 GMT Content-Type: text/html Connection: keep-alive Content-Length: 1285 Accept-Ranges: bytes Last-Modified: […]

这是一个黑客攻击的尝试吗? (CENTOS,NGINX日志文件)

这是我从/var/log/nginx/error.log文件中find的。 2012/02/23 04:28:32 [error] 1704#0: *2 open() "/usr/share/nginx/html/MyAdmin/scripts/setup.php" failed (2: No such file or directory), client: 116.255.168.108, server: localhost, request: "GET /MyAdmin/scripts/setup.php HTTP/1.1", host: "199.180.129.222" 这是一个黑客的尝试? 幸运的是,我还不够聪明,成功地build立了PHP环境… 还有一些有趣的事情: 2012/02/23 04:28:31 [error] 1704#0: *1 open() "/usr/share/nginx/html/w00tw00t.at.blackhats.romanian.anti-sec:)" failed (2: No such file or directory), client: 116.255.168.108, server: localhost, request: "GET /w00tw00t.at.blackhats.romanian.anti-sec:) HTTP/1.1", host: "199.180.129.222" 任何build议,防止这样的事情?

如何解决nginxconfiguration中的“404 not found”错误

我刚刚在debian上安装了nginx,并在nginx.conf文件中做了基本configuration(添加服务器部分) user www-data; worker_processes 1; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; # multi_accept on; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; # tcp_nodelay on; # gzip on; # gzip_disable "MSIE [1-6]\.(?!.*SV1)"; # include /etc/nginx/conf.d/*.conf; # include /etc/nginx/sites-enabled/*; server { listen 80; server_name localhost; […]

我怎样才能让nginx总是返回一个HTTP 503?

我在多个其他服务器上的应用程序前面使用HAproxy。 我想在本地的nginx实例中设置一个虚拟主机,每个请求只提供一个503(当所有的后端都closures时用作“备份”服务器)。 我知道如何设置自定义错误页面(如我如何使Nginx在我的代理应用程序服务器closures时返回HTTP 503? ),但是我怎样才能使得每个请求都返回一个503?

如何告诉nginx只为一个虚拟主机托pipe域提供https服务?

我有一个运行ubuntu和nginx 0.8.4的ec2实例,虚拟主机使用http服务几个不同的域,但是一个使用SSL / https。 安全域configuration: server { listen 443 ssl; server_name "securedomain.tld"; ssl_certificate /etc/nginx/certs/securedomain.tld.crt; ssl_certificate_key /etc/nginx/certs/securedomain.tld.key; if ($host != $server_name) { return 444; # this won't work because HTTPS communication has # been already started, warning message is displayed } // … } 不安全的域configuration: server { listen 80; server_name "unsecuredomain.tld"; // … } 现在,使用https服务的域名正在赶上所有的https域名,对于所有的托pipe域名…这意味着https://unsecuredomain.tld/将显示一个警告,实际上从securedomain.tld 问题是,有没有办法阻止nginx提供所有使用https服务的不安全域? […]

Nginx根据上游响应代码返回444

我有nginx安装程序传递到上游使用代理传递。 上游写入返回502 http响应对某些请求,而不是返回502与所有标题我想nginx recoginse这个并返回444,所以没有返回。 这可能吗? 我也尝试在任何50x错误上返回444,但是它也不起作用。 location / { return 444; } location ^~ /service/v1/ { proxy_pass http://127.0.0.1:3333; proxy_next_upstream error timeout http_502; error_page 500 502 503 504 /50x.html; } location = /50x.html { return 444; } error_page 404 /404.html; location = /404.html { return 444; }

Nginx没有loggingPHP错误

当访问我的网站上的一些PHP脚本,我得到了可怕的500错误信息。 我想知道什么是错误的,但是Nginx并没有在我指定的日志文件中logging任何PHP错误。 这是我的服务器块: server { listen 80; server_name localhost; access_log /home/whitey/sites/localhost/logs/access.log; error_log /home/whitey/sites/localhost/logs/error.log error; root /home/whitey/sites/localhost/htdocs; index index.html index.php /index.php; location / { } location ~ \.php$ { fastcgi_pass unix:/tmp/phpfpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { expires max; } } 请注意,一些PHP脚本工作正常,而其他人不。 所以PHP没有全局性的问题,这些脚本中只有一些导致Nginx抛出500错误。 我怎样才能做到这一点? error.log唯一的错误是关于favicon.ico的错误。