Articles of nginx

NGINX重写位置块内的语法

也许是一个愚蠢的问题,但我似乎无法find好的文档或例子… 当你使用位置块来过滤传入的请求时,你是从匹配的位置还是从请求的开始进行重写? 一个例子: location ^~ /category/ { rewrite ^/category/paid-search-news/?$ /tag/paid-search permanent; # this, rewrite ^paid-search-news/?$ /tag/paid-search permanent; # this, rewrite paid-search-news/?$ /tag/paid-search permanent; # or this? }

在php-fpm confs中设置php值而不是php.ini

我想在php-fpm conf文件中设置通常在php.ini中设置的值。 我正在使用nginx。 我已经创build了以下设置,但我不确定这是否可行。 php_value[memory_limit] = 96M php_value[max_execution_time] = 120 php_value[max_input_time] = 300 php_value[php_post_max_size] = 25M php_value[upload_max_filesize] = 25M 你觉得如果这样可以吗? 当一个值在php.ini和php-fpm conf文件中设置时会发生什么? php-fpm覆盖了ini之一? 最后,这不是一个问题,我可以为所有虚拟主机设置不同的值? 我的意思是php.ini似乎是一个全局设置,而这是主机的依赖。 不同的主机可以运行不同的内存限制等?

Nginx – 转发HTTP AUTH – 用户?

我对Nginx和Jenkins(Hudson)有些麻烦。 Iam尝试使用Nginx作为Jenkins实例的反向代理和HTTP基本authentication。 它的工作到目前为止,但我不知道如何通过标题的AUTH用户名? location / { auth_basic "Restricted"; auth_basic_user_file /usr/share/nginx/.htpasswd; sendfile off; proxy_pass http://192.168.178.102:8080; proxy_redirect default; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwared-User $http_authorization; proxy_max_temp_file_size 0; #this is the maximum upload size client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; […]

Nginx 10k并发连接

我们无法在nginx中处理超过3k个并发请求(Connecton超时)。 我们也将ulimit更改为20000.以下是我的nginx.conf和sysctl.conf文件: user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 5000; use epoll; # multi_accept on; } # took it in next line worker_rlimit_nofile 100000; http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 600; send_timeout 600; proxy_connect_timeout 600; proxy_send_timeout 600; proxy_read_timeout 600; reset_timedout_connection on; types_hash_max_size 2048; client_header_buffer_size 5k; open_file_cache max=10000 inactive=30s; open_file_cache_valid 60s; […]

我怎样才能阻止错误的主机头集请求?

我使用nginx来服务我的网站。 我想阻止与HTTP“主机”标题不匹配我的网站的域的所有请求。 更具体地说,我的nginx.conf包含这两个服务器块: server { # Redirect from the old domain to the new domain; also redirect # from www.newdomain.com to newdomain.com without the "www" server_name www.olddomain.com olddomain.com www.newdomain.com; listen 80; return 301 $scheme://newdomain.com$request_uri; } server { server_name newdomain.com localhost; listen 80; # Actual configuration goes here… } 我想拦截(即“返回”444状态码)任何其主机不是www.olddomain.com,olddomain.com,www.newdomain.com或newdomain.com的stream量。 我怎样才能做到这一点?

php-fpm:帮助理解start_servers,min_spare_servers,max_spare_servers

我试图调整我的服务器的我的php-fpm安装,我无法弄清楚如何处理pm.start_servers , pm.min_spare_servers和pm.max_spare_serversvariables。 我正在使用pm = dynamic pm.max_children是完全清楚的。 每个subprocess一次为1个Web客户端提供服务。 好。 什么是“服务器”呢? 显然,根据我有的默认configuration,1个服务器可以服务超过1个孩子。 什么是上限? 我应该使用什么作为经验法则为孩子/服务器的#? 或者它是相关的? 在某个论坛上,有人声称服务器的数量应该是2 x cpu的核心,但是我已经看到了build议的configuration,其中数量更高,40-50。 PHP文档和许多“调优php-fpm”文章都没有帮助。

nginx与Memcache Vs Varnish

我想知道是否有人对Varnish Vs Memcache有任何意见/基准/build议用于服务内容(通常根据请求中的参数2-5kb的JS文件;可能有数以千计的diff文件) 目前我们使用nginx + Varnish + LAMP来做到这一点。 我正在阅读有关nginx的memcached模块,并想知道是否有人在Memcache中caching内容的任何基准,并直接从nginx提供服务(或从LAMP incase错过),而不是将请求传递给Varnish,让它做同样的工作。 总的来说,是否有任何设置和获得(以及随时清除)内容的基准(通常2-5kb)与Memcache Vs光油 谢谢

为weberver用户设置$ PATH

我试图用包括web服务器用户(即www-data)在内的所有用户为编辑/etc/profile , /etc/environment等不同的方法添加$PATH 。在任何情况下,它都可以在terminal中运行, PHP中的命令。 例如terminal中的echo $PATH显示可用的path,包括我添加的; 但是,PHP中的shell_exec('echo $PATH')显示了没有添加path的原始path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 我怎样才能设置全球$ PATH可以由networking服务器用户使用? 我在Ubuntu / Debian上使用nginx。 我试图编辑/etc/init.d/nginx ,我认为这是nginx的起点,但是没有效果。

HAProxyredirect和基于URI的匹配

我试图build立一个testinghaproxy服务器,将涵盖2个基本领域。 如果用户正在使用http,但只有在特定的uri部分不存在的情况下才能自动redirect到https。 例如,如果用户访问http://www.test.com,他们将被redirect到https://www.test.com 。 但是,如果用户转到https://www.test.com/blog或http://www.test.com/blog,他们将被redirect到http://www.test.com/blog 。 这是我目前的testinghaproxy.cfg。 我正在运行haproxy 1.5-dev17 任何帮助,这是非常感谢。 global log 127.0.0.1 local0 log 127.0.0.1 local1 notice maxconn 15000 user haproxy group haproxy defaults log global mode http option httplog option dontlognull option abortonclose option http-server-close option redispatch retries 3 timeout queue 600s timeout connect 9s timeout client 60s timeout server 60s balance roundrobin […]

使用Nginx将子pathredirect到外部主机

我需要在Nginx中创build一个非常简单的映射,将子pathredirect到位于同一子网中的另一台服务器。 Nginx服务器:192.168.0.2 Tomcat服务器:192.168.0.3:8443 我试图把这个在服务器部分 location /tomcatapi/ { rewrite /tomcatapi/(.*) $1 break; proxy_pass http://192.168.0.3:8443; } 但所有我访问http://www.myservice.com/tomcatapi/是一个500错误页面和nginx日志文件我有这个错误: the rewritten URI has a zero length 我在这个configuration文件中缺less什么?