Articles of nginx

Nginx的前端,Apache的后端,太多的时间等待连接

我使用Apache作为后端与suPHP和mod_sec和nginx作为前端代理。 到目前为止,这种方法运行良好,但由于某种原因,Apache突然产生了很多进程,导致CPU负载增加了很多。 我已经减less了worker_connections和所有的超时怀疑有人正在锤击服务器太多,如机器人等,但问题依然存在。 当CPU负载上升时,我检查了Time_Wait连接,并且有一点我有了5000 TIME_WAIT。 CPU负载正在通过屋顶。 任何想法除了以外我还能做些什么: echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse 更新:tw_reuse有一点帮助,但我必须分析一下。 还有什么我可以尝试获得更多的信息?

Nginx:基于领域的Auth Basicselect性开启/closures

我在LEMP堆栈上运行SugarCRM,并使用auth_basicclosures它。 这工作正常,标题显示: WWW-Authenticate: Basic realm="Username and Password are required" SugarCRM中的一些文件通过PHPbuild立了自己的http auth,比如ical_server.php,它在头部显示: WWW-Authenticate: Basic realm="SugarCRM iCal" X-Dav-Powered-By: PHP class: HTTP_WebDAV_Server_iCal 我试图绕过auth_basic这个文件,或者至less我自己的领域,第一个上面显示。 location = /ical_server.php { auth_basic "off"; } 但是,这closures了这两个领域。 换句话说,它完全closuresauth_basic,不分青红皂白地。 有没有办法有select地closures一个http基本身份validation领域的select? Nginx的文档似乎暗示没有,如果这是真的,那么是否有另一个,也许迂回的方式来实现呢? 比如正式开启我的领域的正则expression式? 伪代码: location != /ical_server.php { auth_basic "Username and Password are required"; auth_basic_user_file /var/web/webaddress.tld/private/.htpasswd; } 虽然我不认为负面的匹配是可能的。 有任何想法吗?

Apache .htaccess规则中的特殊nginx热链接保护转换

在Apache中,我有以下反向重写规则,我希望在nginx中有这个规则。 我看到cookie或引用规则示例。 但是两者都没有结合,所以我不知道如何去做这件事。 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_REFERER} !^$ [OR] RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?domain\.com.*$ [NC] RewriteCond %{HTTP_COOKIE} !^.*_.*$ RewriteRule \.(flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js|htc|woff|otf|eot|ttf)$ – [F,NS,L] </IfModule> 这是一个轻松的规则,允许空的引用,如果与一个已知的cookie发送(例如_ )。 但是当使用无效的域引用者时,它将拒绝没有设置cookie的访问。

在定制authentication之后使用NGINX访问Apache页面

我正在使用Ubuntu 14.04,其中apache运行在端口8080上,而Nginx运行在端口80上 我使用下面的代码来访问使用nginx与我自己的login页面进行身份validation,而不是默认login页面的Apache页面: server { listen 80; # listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /var/www/; index index.php index.html; # Make site accessible from http://localhost/ server_name localhost; location ~ \.php$ { proxy_pass http://localhost:8080; 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_set_header X-Forwarded-Proto $scheme; auth_basic "Restricted"; auth_basic_user_file /etc/nginx/.htpasswd; #proxy_set_header Authorization "Basic YWRtaW46YWRtaW4="; error_page […]

Nginx不在nginx.conf中指定的位置寻找ssl cert

nginx conf看起来像这样: server { ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/4096_SSL.key; systemctl status nginx.service显示了这个: nginx: [emerg] BIO_new_file("/etc/nginx/nginx.crt") failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/etc/nginx/nginx.crt','r') error:2006D002:BIO routines:BIO_new_file:system lib) 为什么不是nginx在指定的完整path中查找文件?

Nginx的多个下载冻结

我们对Nginx有一个问题。 我们有一个filehoster,我们的用户可以同时下载3个文件。 当我们开始2下载没关系,3下载速度慢,4下载和更多是不可能的。 你知道问题可能出现在哪里吗? 这是我的nginx.conf: user www-data; worker_processes 8; pid /var/run/nginx.pid; worker_rlimit_nofile 20240; events { worker_connections 10240; multi_accept on; use epoll; } http { proxy_connect_timeout 600s; proxy_send_timeout 600s; proxy_read_timeout 600s; fastcgi_send_timeout 600s; fastcgi_read_timeout 600s; ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; […]

Nginx的SSL卸载导致加载页面不完美的客户端

我有后端服务器在http和https上运行一个网站。 使用nginx反向代理: server { listen front_IP:80; server_name dns_name; allow all; location / { proxy_pass http://backend_IP; proxy_set_header Host $host; } 和 server { listen front_IP:443; server_name dns_name; allow all; ssl on; ssl_trusted_certificate CA_file_Path; ssl_certificate Cert_file_path; ssl_certificate_key Key_file_path; location / { proxy_pass https://backend_IP; proxy_set_header Host $host; } } 都正常工作。 但是(对于ssl卸载)在https上进行监听并且对http进行proxy_pass(反之亦然)会导致客户端不完美地加载页面。 为了更准确,客户端不会加载任何主题,CSS或模板。 有些事情是这样的我的意思是: server { listen front_IP:443; server_name […]

带尾随斜线的Nginx别名

我有一个子网站在这样的父母网站下工作: http://example.org/ sub-site ( http://example.org/ sub-site / works too) 一切似乎都运作良好,其中包括: ./ 子网站 /子网段 但这个url不会工作(它返回一个404): ./ 分网站 / 分节 / 我目前的Nginx代码如下: location ^~ /sub-section { alias /usr/share/nginx/html/sub-section/public; try_files $uri $uri/ @sub-section; location ~* \.php$ { fastcgi_pass 127.0.0.1:9000; include /etc/nginx/fastcgi_params; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; } } location @sub-section { rewrite ^/sub-section/(.*)+$ /sub-section/index.php?$1 last; } […]

如何用源代码编译NginxconfigurationHHVM?

我在Debian 7上安装了Nginx 1.8(源码编译): cd /opt/ sudo wget http://nginx.org/download/nginx-1.8.0.tar.gz sudo wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz sudo tar -zxvf nginx-1.8.0.tar.gz sudo tar -zxzf ngx_cache_purge-2.3.tar.gz cd /opt/nginx-1.8.0/ sudo ./configure –prefix=/opt/nginx –user=nginx –group=nginx –with-http_ssl_module –with-ipv6 –add-module=/tmp/ngx_cache_purge-2.3 sudo make && make install sudo adduser –system –no-create-home –disabled-login –disabled-password –group nginx sudo wget -O init-deb.sh http://www.linode.com/docs/assets/1538-init-deb.sh sudo mv init-deb.sh /etc/init.d/nginx sudo chmod +x /etc/init.d/nginx […]

Nginx,反向代理,只caching一些路由

我有一个在英国运行的RESTful API,但不知何故,AU用户的速度非常慢。 所以我想要做的是在AU服务器上放置一个nginx代理,并caching一些路由1,10和60分钟,而不要caching其余的。 我不确定这是否可以用nginx实现,但这是我做的; server { listen 80; server_name proxycache.domain.com; access_log /var/log/nginx/reverse.log upstreamlog; proxy_ignore_headers Set-Cookie; proxy_hide_header Set-Cookie; proxy_ignore_headers Cache-Control; proxy_ignore_headers Vary; proxy_ignore_headers X-Accel-Redirect; proxy_ignore_headers X-Accel-Expires; proxy_ignore_headers X-Accel-Limit-Rate; proxy_ignore_headers X-Accel-Buffering; proxy_ignore_headers X-Accel-Charset; proxy_ignore_headers Expires; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host data.domain.com; add_header X-Cache $upstream_cache_status; proxy_redirect off; proxy_cache STATIC; proxy_cache_key $host$uri$is_args$args; proxy_cache_use_stale error timeout invalid_header […]