Articles of nginx

我们是否获得了一个access.log条目,用于cachingnginx中的内容

对于一个看起来像的configuration http { proxy_cache_path /etc/nginx/cache keys_zone=one:10m; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; server { proxy_cache one; listen 80; server_name xyin www.xyin; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_pass http://127.0.0.1:1234; proxy_redirect off; } add_header Access-Control-Allow-Origin *; } } 我正在做ab(apache基准)。 有趣的是,我没有在caching内容的access.log文件中看到任何东西,我可以看到一些文件popup在我指定的caching目录中。 这是行为的预期,caching的内容不会出现在access.log? 它是可configuration的吗? 也通过nginx文档,找不到任何与此有关的东西。

nginx用php和两个node.js路由

我有两条路线,我想通过两个节点进程(websocket路由,angular度的应用程序),而第三条路线需要传递给一个PHP应用程序,充当angular应用程序的restAPI。 我不是非常精通nginx 这是我的尝试: user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { 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; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## […]

来自代理caching的400个不良请求

所以我们有一个nginx代理caching,即使在npm停机的情况下也可以保持正常运行。 有时这个服务器(显然每隔几个月)就开始为某个特定的软件包返回400 bad request 。 我认为这是一个损坏的caching或什么的。 所以我们擦拭caching,然后我们可以再次npm install 。 我们试着简单的重启服务器,但结果还不够。 值得一提的是,对于同一个对象(即tar.gz文件),实际的源代码(npm本身)会返回200OK。 这里是configuration: https : //github.com/parris/private-npm-registry/blob/master/nginx/server.conf (随时探索周围的文件)。 configuration看起来像这样: server { listen 8888; server_name localhost; location / { proxy_pass https://registry.npmjs.org/; proxy_cache npm; proxy_cache_valid 200 302 3d; proxy_cache_valid 404 1m; # npm adds "_resolved": 'registry.npmjs.org/xyz.tgz" to package.json files # this rewrites things correctly sub_filter 'registry.npmjs.org' 'localhost:8888'; sub_filter_once off; […]

增量子域名暴力强制?

目前正在寻找坐落在AWS ELB后面的小型清漆/ nginxnetworking服务器组。 最近主域的监控把大量命中到不存在的子域地址。 在进一步检查清漆日志时,它揭示了一些IP运行的python代理,试图通过没有单词列表来增量地强行加载子域。 Atm它没有超过4个字符,即。 aaaa.primarydomain.com和。 目前在fau9.primarydomain.com 404的速度和服务造成了一个小的麻烦,所以在设置了一定的门槛和阻断之后,以及联系滥用的部门进行检测。 到目前为止,大约有10个IP都是通过btcentralplus.com进来的,后来被封锁了。 它似乎来自一个业余的僵尸networking,对IP的调查揭示了与英国家庭和小型商业networking的一致性。 更重要的是动机,对于这样的攻击我感到目瞪口呆。 对于初学者来说,没有什么可以通过这个获得,即使有明显的迹象,试图增加域名列表的力量似乎超越了愚蠢? 这不是绝对的威慑。 我们提出的唯一build议是脚本 – 小孩失败,一个奇怪的蠕虫试图上帝知道什么或某种假的stream量生成? btcentralplus是唯一的常见variables,似乎在处理滥用投诉方面毫无用处。 如果他们试图在Web服务器日志中抽出反向DNS条目,例如可能会公开的? 但即使如此,似乎离奇。

将$ REMOTE_ADDR设置为真实的客户端IP

我正在用Nginx在Heroku上托pipe一个WordPress站点 。 DNS在CloudFlare后面。 我的WordPress插件报告Heroku的IP而不是真正的客户IP。 我有以下的Nginx规则: location / { try_files $uri $uri/ /index.php?$args; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $http_cf_connecting_ip; } # Allow for internal Heroku router – 10.xxx set_real_ip_from 10.0.0.0/24; # Allow for external CloudFlare proxies – https://www.cloudflare.com/ips set_real_ip_from 199.27.128.0/21; set_real_ip_from 173.245.48.0/20; set_real_ip_from 103.21.244.0/22; set_real_ip_from 103.22.200.0/22; set_real_ip_from 103.31.4.0/22; set_real_ip_from 141.101.64.0/18; set_real_ip_from 108.162.192.0/18; set_real_ip_from […]

HHVM随机停止运行

的背景 最近我已经改变了php5-fpm而hhvm ,那真是他们所说的,“holly performance grialed” 我已经安装hhvm删除php5-fpm(真的是一个后备需要??)按照此说明: https : hhvm 。 我在这个VPS里有多个网站(域),其中大多数是wordpress + nginx + W3TC + Ubuntu 12.0.4p + MariaDB 10ish 主要问题 由于变化,随机hhvm突然停止运行。 不知道为什么,所以我决定按照本教程的最后一步,安装ps-watcher并检测服务是否未运行,并每5秒检查一次以重新启动它。 configuration hhvm.conf: location ~ \.(hh|php)$ { proxy_intercept_errors on; #error_page 502=@fallback; try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_keep_conn on; fastcgi_buffer_size 128k; fastcgi_buffers 256 16k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; include fastcgi_params; fastcgi_index index.php; fastcgi_param […]

为什么这个Nginx的wwwredirect不工作?

我在使用nginx服务器的wwwredirect时遇到问题。 服务器运行2个站点: example.com和blog.example.com 。 服务器configuration: nginx / 1.4.6(Ubuntu) Ubuntu 14.04.1 LTS 相关DNSlogging: www.example.com. 1800 IN CNAME example.com. blog.example.com. 1800 IN CNAME example.com. nginxconfiguration: /etc/nginx/sites-enabled/example.com server { server_name www.example.com; return 301 $scheme://example.com$request_uri; } server { server_name example.com; root /var/www/example.com/html; } /etc/nginx/sites-enabled/blog.example.com server { server_name blog.example.com; root /var/www/blog.example.com/html; } 预计: www.example.com将redirect到example.com 实际: www.example.com正在显示blog.example.com 有谁知道为什么redirect不能按预期工作?

Keepalive Nginx-Haproxy-Apache链的最佳实践

我使用Nginx来提供静态内容,Haproxy代理请求到通过Zookeeper发现的多个Apache2后端。 Nginx – > Haproxy – > Apache2 根据Nginx官方网站的说法,它将这种长时间保持连接的方式聚集在这样的后端,将连接数量降到最低。 因此,我的假设是,Nginx是Keepalive必须在哪里,并设置一个更大的价值,在我的情况“keepalive_timeout 600”; 然后在本地端口上点击Haproxy,Apache后端的“httpclose”选项打开: 选项httpclose启用或禁用被动H​​TTP连接closures HAProxy还不支持HTTP保持活动模式。 所以在默认情况下,如果一个客户端在这种模式下与服务器进行通信,它将只分析,logging和处理每个连接的第一个请求。 要解决这个限制,可以指定“选项httpclose”。 它将检查每个方向是否已经设置了“连接:closures”标题,并且如果缺失则添加一个标题。 每一端都应该在每次传输之后主动closuresTCP连接,从而导致切换到HTTPclosures模式。 任何“连接”标题不同于“closures”也将被删除。 这个选项可以设置在前端和后端。 如果前端或后端中至less有一个持有连接,则启用该function。 然后Haproxy将连接路由到Apache2。 所以,我的假设是,在这种情况下,我将不得不closuresApache的keepalive,因为a)Nginx聚合连接b)Haproxyclosures它们。 我的推理是否正确,在这样的链条上优化Keepalive会更好吗? 更新: 这个 ServerFault主题指出,从Haproxy中移除Keepalive也是有益的(因此我们可以去掉httpclose),因为Haproxy和Apache之间的延迟太低,无法消除握手。 所以我们用Nginx(KA) – > Haproxy(没有KA) – > Apache(没有KA) 这是更好的select吗?

Nginxredirect到URL中指定的端口

是否有可能使用Nginx从这样的URL代理: http://example.com/service/1234/foo.php?… 到像这样的内部服务: http://example.com:1234/foo.php?… 也就是说,从URL中提取一个数字,并将其作为端口号使用到同一台服务器上? rewrite似乎仅限于操作端口后的URL部分,我不认为proxy_pass可以从中访问正则expression式的子string。 我试图解决的具体问题是,我的服务都可以在端口80上访问,因为各种公司和公共networking阻塞了实际运行服务的异国情调的端口。 所以它必须是一个反向代理,而不是一个redirect。 此方法适用于单个端口: location /service/5010 { rewrite ^/service/5010/(.*)$ /$1 break; proxy_pass http://127.0.0.1:5010; } 但问题是如何使5010只是从URL中提取的参数。

Nginx代理Nodejs(Dokku)。 CORS响应标题不通过

我正在使用Dokku在DigitalOcean上托pipe我的应用程序。 Dokku运行nginx 1.6来模拟类似Heroku的代理Docker应用程序。 该应用程序的所有共享类似的默认configuration,如下所示。 我的Node.js服务器使用CORS中间件告诉浏览器允许www.myapp.com打电话给api.myapp.com: 这在我的本地计算机上正常工作。 当我部署它,我在浏览器中得到一个CORS错误: XMLHttpRequest cannot load https://api.myapp.com/r_u_up. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.myapp.com' is therefore not allowed access. The response had HTTP status code 502. 所以,跆拳道,结束了。 我发现这个nginx CORSconfiguration,但它似乎非常crufty。 这是旧的代码,还是最好的方法? 这个插件使用该configuration。 我更喜欢简单的configuration,只是通过响应头。 我的应用程序不需要nginx来拦截它们。 我如何configuration? 应用程序的nginx.conf的: upstream www { server 172.17.0.135:5000; } server { listen [::]:80; listen 80; […]