Articles of nginx

Nginx反向代理和丢失的尾部斜杠redirect

我有一个nginx的问题,作为反向代理和代理服务器。 在前台服务器上,我的configuration是: server { server_name example.com; location / { 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_pass http://10.2.2.1:8999; } } 而在代理服务器上: server { listen 10.2.2.1:8999; server_name example.com; autoindex on; location / { root /var/www/; } } 最后,在这个代理服务器上,有一个/var/www/test目录,里面有一些文件。 当我尝试访问http://example.com/test (没有结尾的斜杠!)时,出现问题:我的浏览器被redirect到http://example.com:8999/test/ …如果我尝试访问到http://example.com/test/ ,没问题。 我已经尝试了proxy_redirect语句,据我所知,允许反向代理重写Location标题,以避免这种行为,但这并没有为我工作。 为什么?。 我的第二个问题是,为什么profixied nginxredirect到这个URL? 我怎么能阻止它做到这一点? 感谢提前任何帮助。

以nginx的forms提供URL以斜线结尾的页面

我想让nginx为/foobar/提供一个HTML文件。 我尝试了2个configuration,都没有工作。 在Apache中,你可以这样做: AliasMatch ^/foobar/$ /home/admin/foobar/foobar.html 我第一次尝试: location /foobar/ { alias /home/admin/foobar/foobar.html; } 去/foobar/显示一个500错误页面。 错误日志说: 2011/08/05 04:12:35 [alert] 32465#0: *1 "/home/admin/foobar/foobar.htmlindex.html" is not a directory, … 这很奇怪 为什么它会在文件path的末尾添加“index.html”? 我下一次尝试: location ~ ^/foobar$ { alias /home/admin/foobar/foobar.html; } 去/foobar使我的浏览器下载文件。 这很奇怪 为什么会发生? 我能够得到它与这个工作: location /foobar.html { alias /home/admin/foobar/foobar.html; } 这工作,但它有错误的url。 它有/foobar/ /foobar.html而不是/foobar/ 。 我该怎么做呢?

将请求的IP从Nginx转发到Apache的日志

我使用nginx作为Apache的前端反向代理,我在nginx里有如下configuration: location / { if (-f $request_filename) { add_header X-Static hit; access_log off; } if (!-f $request_filename) { proxy_pass https://127.0.0.1:8000; add_header X-Static miss; } 用本地端口8000监听apache。 当我看着Apache的日志时,所有的请求都来自于127.0.0.1:443(这是nginx所在的地方)。 我想转发真正的IP到Apache,以便它正确地存储在日志中。 我试图将下面的行添加到位置块无济于事 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 我在这里错过了一步吗? 我需要更改apache的日志格式吗? 它正在使用默认的组合日志。

Nginx重写/path?参数/longer/path.html?params

简单的一个 – 但我宁愿使用位置+重写与如果+重写(如果是邪恶的,正确的?) 旧url:/ app?key = 1234 新的url:/system/app.html?key=1234 试着 location /app { rewrite ^/app$ /system/app.html break; } 只有404 …

Nginx + PHP-FPM + APC + Varnish + Memcached:高内存/交换消耗?

我已经在Linode使用1024 MB RAM,Ubuntu 11.04和Nginx + PHP-FPM + APC Varnish + Memcached主动运行VPS。 我已经用WordPress 3.2.1设置了几个testing博客,一切正常,性能testing看起来很有希望: # ab -n 1000 -c 100 http://mydomain.com/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking mydomain.com (be patient) Completed 100 requests Completed 200 requests Completed 300 […]

JMeter的Nginx + PHP-FPM基准testing – Spikes

设置是 EC2微型实例 带有FPM的Nginx 1.0.0.5 PHP 5.2.17与CGI 应用程序连接到RDS上的MySQL 收集监视 JMeter在同一个EC2区域的其他服务器上使用(所以延迟不是问题)。 问题是从Collectd生成的graphics,结果是非常spikey。 例如,20万分钟的请求花了20分钟,模式就像1分钟的请求1分钟,然后几乎平坦(甚至不到100)2分钟的请求,重复。 在这里达到极限的唯一资源是100%的CPU。 其余的还没有被充分利用。 哎呀,我以前在静态页面上尝试过,并获得几乎相同的模式: 巨大的穗 – 扁平 – 巨大的穗 我在这里俯瞰什么? 我已经照顾的一些东西: rlimit设置得非常高 nginx工作连接设置为8192 PHP-FPM最大的孩子设置为140 下面是从一个运行(共20万个请求) 谢谢。

nginx + munin“内部redirect周期”

我有一个运行nginx的SSL域,我想能够访问我的munin图/统计在该域。 所以,在域的server块中,我添加了这个: location = /munin/ { alias /var/cache/munin/www/; } 理论上,我应该可以访问http://example.com/munin并显示/var/cache/munin/www/index.html 。 但是,我得到一个500错误,并在error.log这个消息: 2011/08/26 15:21:25 [错误] 19089#0:* 31218重写或内部redirect周期内部redirect到“/index.html”,客户端:1.2.3.4,服务器:domain.com,请求:“ GET / munin / HTTP / 1.1“,主机:”domain.com“ 我尝试了一堆不同的东西,但似乎没有任何工作。 如果有人能够澄清这种情况,我会很感激,也许会想出一个解决scheme。 谢谢! 🙂 这是域的完整configuration,如果有帮助: server { listen 443 default ssl; ## listen for ipv6 ssl_certificate somewhere; ssl_certificate_key somewhere; root /srv/www/domain.com/wwwroot; index index.html index.htm index.php; access_log /srv/www/domain.com/logs/access.log combined; error_log /srv/www/domain.com/logs/error.log; server_name […]

nginx重写为按字母顺序的子目录

我试图将下面的Apache mod_rewrite规则转换成适当的nginx格式: RewriteCond %{REQUEST_FILENAME} (.*)/([^\/])([^\/]+)/?$ RewriteCond %1/%2/%2%3 -d RewriteRule ^/?.* /%2/%2%3 [L] 在实践中,这个规则重写裸目录请求,将它们放在基于第一个字符(区分大小写)的父目录中,所以http://example.com/foobar变成http://example.com/f/foobar ,等等。 其他的一切都是静态的内容,或者PHP,并通过FastCGI传递,并有location处理程序。

从nginx到Jetty的代理

我正在从nginx代理请求到Jetty,但我有Jetty收到请求的问题。 Jetty请求显示请求IP地址是127.0.0.1。 但是我想要真正的服务器IP,我的站点有多个域,所以当请求从某个域名到我的服务器时,它也必须在Jetty请求中可用。 nginxconfiguration: server { listen 80; ## listen for ipv4 listen [::]:80 default ipv6only=on; ## listen for ipv6 server_name localhost; access_log /var/log/nginx/localhost.access.log; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header X-Real-IP $remote_addr; } } Servlet请求: Dump Servlet getMethod: GET getContentLength: -1 getContentType: null getRequestURI: /dump/info getRequestURL: http://127.0.0.1:8080/dump/info getContextPath: getServletPath: /dump getPathInfo: /info getPathTranslated: /tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/info getQueryString: […]

哪种电子邮件服务在这种情况下效果最好?

可能重复: 推荐的SMTP中继服务 我在Linode使用VPS服务器来托pipe几个Drupal网站。 对于networking,我使用的是Nginx,所有电子邮件都由Google Apps托pipe。 我需要能够允许Drupal发送电子邮件,但是安装postfix是最好的方法,还是我可以放弃更小的东西,因为我需要在服务器上的所有外发电子邮件? 谢谢