Articles of nginx

Nginx可以caching包含X-Accel-Redirect头的上游响应吗?

我正在使用nginx作为应用程序服务器前面的反向代理。 应用程序响应一个X-Accel-Redirect头文件,告诉nginx要提供哪个静态文件。 我希望能够做的是让nginxcaching一些上游回应,所以它可以提供正确的文件,而无需点击应用服务器。 不幸的是,这不起作用:nginx似乎拒绝用X-Accel-Redirect头caching任何响应。 如果我不使用X-Accel-Redirect并让应用程序服务器返回文件本身,那么caching完美无缺。 然而,这并不是非常有效,因为应用程序服务器必须从磁盘读取文件并将其发送给nginx,nginx然后将文件写回磁盘(在其caching中)并将其发送到客户端。 这里是我的nginxconfiguration的精简版本: proxy_cache_path /tmp/nginx-cache keys_zone=testzone:10m; server { location / { proxy_cache testzone; proxy_pass http://localhost:8000/; } location /static-files/ { internal; alias /var/static-files/; } } 有谁知道我试图做什么是可能的? 我的怀疑是,当nginx发现X-Accel-Redirect头部时,它立即跳转到处理提供的URI并跳过正常的caching逻辑,但是确认这个会很好。

nginxredirect回remote_addr IP

我试图设置nginx 1.0.12作为Apache 2.2.15的代理,但面临一个奇怪的问题。 我连续三天无法解决。 我有testing网站ccraft.info并已安装roundcube / roundcube子目录。 所以这里是问题: 如果您尝试打开http://c-craft.info/roundcube,您将得到奇怪的redirect到您自己的IP地址。 所以似乎nginx试图从remote_addr下载静态文件。 但是,如果你将添加尾随斜线像圆形/这将工作。 另一个例子:尝试打开http://www.contra.lv – 你也将redirect回你自己的IP地址,并再次尝试从remote_addr下载静态文件。 有趣的是,通过Apache连接工程很好: c-craft.info:9091/roundcube contra.lv:9091 我真的需要你的build议如何解决它,因为我卡住…这是我目前的configuration文件: nginx.conf user nginx; worker_processes 2; pid /var/run/nginx.pid; events { worker_connections 2048; use epoll; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr – $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log; error_log […]

状态码在nginx的try_files指令中

是否有可能使用当前状态代码作为try_files的参数? 例如,我们尝试提供特定于主机的503静态响应,或者如果找不到,则为全服务器回退: error_page 503 @error503; location @error503 { root /path_to_static_root/; try_files /$host/503.html /503.html =503; } 有一些这些指令,所以这样做会很方便: error_page 404 @error error_page 500 @error error_page 503 @error location @error { root /path_to_static_root/; try_files /$host/$status.html /$status.html =$status; } 但是, variables文档没有列出我们可以用来做这件事的任何东西。 有没有可能,还是有其他的方法来做到这一点?

全局nginx错误页面不redirect

我想知道是否有可能在没有redirect的情况下(在浏览器的地址栏中更改URL)在nginx中有全局error_page指令。 我知道这是可能的,通过使用一个命名的位置,但全局错误页面是在http块中声明,不允许位置指令。 我有一些虚拟主机在我的configuration,我试图避免将此添加到当前和所有未来的虚拟主机。 我目前正在使用nginx 1.3.0,如果这有所作为。

访问注销nginx不工作?

我有位于/etc/nginx/drop.conf中的以下drop.conf文件 # if you don't like seeing all the errors for missing favicon.ico requests # sent by a lot of browsers in root we dont need to log these – they mean extra IO location = /favicon.ico { access_log off; log_not_found off; } # if you don't like seeing errors for a missing robots.txt in […]

基于url参数的nginxdynamic代理

我从外部网站加载图像,我想要在3D WebGLcanvas中使用。 但是由于原产地,这是不允许的。 我从网页生成的URL如下: http://domain/somename/imagesproxy?url=http%3A%2F%2Fanothersite%2Fimage.png 现在我想proxy_pass我假设,包含在请求中的URL。 location /somename/imagesproxy { proxy_pass … proxy_set_header host localhost; } 如何让nginxdynamic代理不同的URL

Nginx作为反向代理:如何正确configuration网关超时?

我们已经将Nginxconfiguration为Apache服务器场的反向代理,但是我遇到了网关超时问题。 我们的目标是:“在一秒内发送请求,但如果真的需要更长的时间,则无论如何都要发送”,这对我来说意味着“尝试第一个上游的Apache服务器最多500毫秒,如果我们得到一个超时/一个错误,尝试下一个,直到我们终于成功。“ 现在我们的相关configuration是这样的: location @proxy { proxy_pass http://apache$request_uri; proxy_connect_timeout 1s; proxy_read_timeout 2s; } […] upstream apache { server 127.0.0.1:8001 max_fails=1 fail_timeout=10s; server 10.1.xx:8001 max_fails=1 fail_timeout=10s backup; server 10.1.xx:8001 max_fails=1 fail_timeout=10s backup; server 10.1.xx:8001 max_fails=1 fail_timeout=10s backup; } 这里的问题是,nginx似乎误解了这一点:“尝试在一秒钟内从整个上游集群获得响应,如果我们不这样做,就会发出50倍的错误 – 没有任何限制尝试任何上游服务器的时间限制”显然不是我们想到的。 有没有办法让nginx做我们想要的?

nginx代理+ ssl + clr“400错误请求”错误

这里有一个情况 – 有一个处理SSL证书的nginx代理,在我们决定添加一个撤销列表pipe理之前,这个代理是安全的。 这是当“ssl_crl”行进场,并拧紧了一切。 server { listen 80; rewrite ^ https://$host$request_uri permanent; } server { listen 443 ssl; server_name example.com; ssl on; ssl_certificate /home/netadmin/keys/tid.crt; ssl_certificate_key /home/netadmin/keys/tid.key; ssl_session_cache shared:SSL:10m; ssl_client_certificate /home/netadmin/keys/personchain.pem; ssl_crl /home/netadmin/keys/personlist.crl; ssl_verify_client on; ssl_verify_depth 2; error_log /var/log/nginx/debug.log debug; location / { proxy_pass http://111.111.111.111:80; } 每当用户尝试使用SSL进行身份validation时,服务器将始终提供“400错误请求”错误。 请注意,完全相似(不同,因为语法)configuration在Apache中完美工作。 现在证书是完美无瑕的,这已经被多次certificate了,例如validation检查 openssl crl -CAfile personchain.pem -inform PEM -in […]

在由nginx代理的机器上设置cookie时出现问题

对于我的一个项目,我需要连接一个长长的机器链,它们本质上代表了彼此的HTTP请求。 它是这样的: Web客户端 – A – B / C – D 当浏览器发出请求时,它首先通过位于用户本地机器上的瘦PHP代理层,其目的是为了解决跨域请求等问题。 它代理机器B – 只是一个nginx实例,它将URL和代理重写为C.在代理D之前,C做了一些必要的修改,获得响应并将其返回给Web客户机。 D是一个无法触及的远程服务API。 我在机器C上设置会话cookie时遇到了问题,它一直到原来的请求。 尽pipe设置cookie是可能的,但是当有新的请求时,Chromenetworking检查器中不可见,并且当我尝试从显然不存在的cookie中获取值时,节点C返回nullpointerexception。 我想,它归结为调整nginx代理请求的方式。

为什么Nginx的proxy_intercept_errors指令需要重写才能正常工作?

以下是Nginx服务器configuration示例。 如果没有“魔法护符”位置块,代理错误内容将导致Nginx 404页面,而不是提供自定义错误页面。 删除proxy_intercept_errors指令会提供正确的代理错误页面,并带有正确的http错误代docker。 不pipe魔法护身符的存在,非恶意错误页面都能正确渲染。 任何想法到底是怎么回事? server { server_name mydomain.com ""; listen 80; root /var/www; error_page 400 401 402 403 404 500 501 502 503 504 /admin/error_page.htm; proxy_intercept_errors on; location /proxy/ { proxy_read_timeout 60s; proxy_set_header Host $host; proxy_pass http://myservers; } location /test404/ { return 404; } location /admin/ { # this line constitute a magical […]