Articles of nginx

在nginx负载平衡中的响应

假设我有nginxconfiguration了3个上游,并且我请求下载一个文件。 三个上游之一将处理请求。 答案是否直接来自上游? 或者将响应来自网关(configuration上游的机器)? 如果是第一种情况,这是如何工作的? 它是否类似于TCP Handoff,但在HTTP级别?

如何有条件地匹配nginx中的位置

我想设置nginx的位置匹配,但只为一个特定的源地址。 不幸的是,如果我已经匹配一个位置,而不是我不能通过到下一个位置的条件。 有什么办法很好地解决这个问题? server { … location / { index app.php; try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /app.php/$1 last; } … location ~ ^/admin { if ($source_trusted = "UNKNOWN") { return 403; } } … location ~ ^/… { fcgi_pass … … } } 使用这个configuration将/admin source设置$source_trusted = OK (通过地理模块)会产生一个404 ,而不是页面加载。

Nginx阻止多个域将所有stream量redirect到https?

我有一台运行nginx 1.6的web服务器,其中包含一个IP地址,并托pipewww.domainname.com以及dev.domainname.com。 我试图find一个聪明的方式来路由所有的HTTPstream量到https,我想确保我的默认服务器是“www”现场版本的时间。 所以最终目标是,除非用户指定https://dev.domainname.com ,否则他们将被redirect到https://www.domainname.com 。 我的nginx.conf设置被configuration为包含'/ etc / nginx / etc / sites-enabled / *'。 所以我的configuration示例位于'etc / nginx / sites-enabled / www.domainname.com'。 另外,要澄清。 当您访问没有www的域名时,我当前的configuration有加载dev站点的问题。 编辑 :我只是在本地尝试这个方法,http和https不允许在'/ etc / nginx / sites-enabled /'中。 有没有更好的解决scheme,或者我应该把这个configuration到nginx.conf? 所以我的问题是有更好的方式来处理这种types的设置? http { # all traffic should be over https listen 80 default; # listen for all server names server_name *.domainname.com; […]

将多个目录限制在相同的IP范围

假设我在nginxconfiguration文件中有以下内容: location ^~ /foo/ { allow 1.2.3.4; allow 5.6.7.8; allow 9.10.11.12; … allow 99.100.101.102; deny all; # rest of directives } 如果我还想限制访问其他几个目录,是否可以这样做,而不必创build另一个块并重新列出IP? 我担心在未来添加和删除IP时会发生变化 – 我不想确保每个块都被更新。 更好的办法是基本上允许我以某种方式“包括”每个块下的IP列表。

在ubuntu服务器的ntpdate更新之后,我总是收到nginx中的旧php文件

当我使用ntpdate ntp.ubuntu.com来同步我的服务器时钟时,发生nginXcaching的问题。 现在,当我请求pathhttp://www.example.com/project/create我收到了我正在处理的旧的PHP文件。 我尝试在nginx.conf中将sendfile设置为off ,甚至在cloudFlare为我的DNSclosurescaching,但没有成功。 当我看着头部分curl -I http://www.example.com/project/create我有以下的回应: HTTP/1.1 302 Moved Temporarily │ Server: nginx │ Date: Fri, 15 Aug 2014 10:51:38 GMT │ Content-Type: text/html │ Connection: keep-alive │ Set-Cookie: PHPSESSID=cihsfrq6aoat5baun8dem01go5; path=/ │ Expires: Thu, 19 Nov 1981 08:52:00 GMT │ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 │ Pragma: no-cache │ Location: http://www.example.com/site/login 我找不到任何nginxcaching文件夹要删除。 […]

查询string为空时如何禁用代理caching?

用nginx我有 server { listen 1.2.3.4:80 proxy_cache_valid 200 302 5m; location / { try_files $uri @upstream; root $root; } } 当我去http://example.com/foobar它会生成一个redirect到http://example.com/foobar http://example.com/foobar?filter_distance=50&…这是访问者依赖,所以我想不caching这个redirect。 查询string为空时,我需要绕过caching。 我有点失落,因为location /foobar将匹配两个。

PHP的FPM状态整理,但从来没有完成

我们正在使用Nginx和PHP-FPM在Ubuntu 14.04上运行Symfony应用程序 问题在于,单个PHP FPM偶尔会挂在我们的生产服务器上。 我有状态页面的输出: pid: 13416 state: Finishing start time: 08/Sep/2014:12:35:29 +1000 start since: 10548 requests: 3 request duration: 158138427297 request method: GET request URI: /app.php?searchText=Search+term&page=2 content length: 0 user: – script: /var/projects/site_path/app.php last request cpu: 0.00 last request memory: 0 我不明白为什么这个过程是悬而未决的。 如果我把这个过程简单化一下就可以了: # strace -p 13416 gettimeofday({1410154710, 385743}, NULL) = 0 我已经检查了Nginx的访问日志,并匹配请求和请求是好的,它返回一个200,没有错误可以复制使用该url)。 任何帮助将不胜感激 […]

redirect循环SSL Nginx Cloudflare

我有CloudFlare的通用SSL。 我想在我的Ghost博客上build立一个永久SSLredirect。 这是我的原始configuration。 它可以单独使用http://example.com和https://example.com server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name example.com; # Replace with your domain root /usr/share/nginx/html; index index.html index.htm; client_max_body_size 10G; location / { proxy_pass http://localhost:2368; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; } } 这是我尝试configuration为从HTTPredirect到HTTPS,但它导致redirect循环 server { listen 80 default_server; server_name example.com; return 301 […]

Nginx将所有www.domainredirect到域,并将所有域redirect到www.domain

我试图让nginx通过添加或删除www来redirect从任何域收到的每个请求。 字首。 这是一个小redirect服务。 如果你指向www.any.domain,它应该将www.any.domain / *redirect到any.domain / *。 如果你指向任何.domain,它应该redirectany.domain / *到www.any.domain / *。 这在实践中不会导致redirect循环,因为这两个域(any.domain或www.any.domain)中只有一个会指向这个服务。 另一个到另一台服务器上的您的网站。 这应该适用于任何域。 数以千计的不同的,所以它必须有一个正则expression式通配符匹配。 事实上,互联网上的任何东西都可以指向它,这不是nginx的担心,因为这将在上面/之前的一层处理。 每一个带有HTTP_HOST头部的请求都会有一个www或者没有,在这两种情况下都应该被redirect,所以服务器应该redirect它接收的所有请求。 域名不以www开头的情况。 很容易,但我不知道如何捕捉它开始与www的情况。 然后只使用域的其余部分。 我试过search,但是a)几乎没有人同时redirect,b)大多数人只关心一个领域,所以他们硬编码和c)一旦你过去,人们往往吟唱“如果是邪恶”。 所以这并没有什么帮助。 这是我现在所拥有的: http { server { listen 80 default_server; server_name _; # add www. to URLs that don't start with it. if ($host !~* ^www\.) { rewrite ^(.*)$ http://www.$host$1 permanent; } # […]

NGINX:很多连接超时错误

我得到这个错误很多: 2014/11/26 21:01:30 [error] 3475#0:* 4028上游超时(110:连接超时),从上游读取响应头 这是我的configuration: user www-data; pid /run/nginx.pid; worker_processes 2; worker_rlimit_nofile 16384; events { worker_connections 4096; use epoll; multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; # free up connection after client stops responding… reset_timedout_connection on; # If the client stops reading data, free up the stale […]