Articles of nginx

在没有PHP错误的Alpine / Nginx / PHP 7.1.2与docker

我正在使用Alpine / Nginx / PHP-FPM 7.1.2。 我无法得到PHP错误的显示或输出到我的Nginx服务器块的error.log 。 access.log似乎工作得很好。 我在www.conf的底部find了/usr/local/etc/php-fpm.d/ php_flag[display_errors] = on php_admin_value[error_log] = /var/log/fpm-php.www.log php_admin_flag[log_errors] = on 在Docker日志中没有任何东西,并且/var/log/fpm-php.www.log也没有错误… 我需要做什么来显示和logging错误? 我也试过错误日志: /proc/self/fd/2

nginx(last / break)重写

我有一个简单的nginx重写在这里,使用永久标志,它工作正常。 location /area1/ { rewrite /area1/(.*)$ / permanent; } 但是,我想保留最初的url,这似乎从研究到只需要最后一个或中断标志。 location /area1/ { rewrite /area1/(.*)$ / break; } 在改变永久性(或最后 )之后,似乎完全忽略了redirect。 请有人可以演示一个工作的内部redirect,保留最初的url – 我知道这应该是简单的,但我已经尝试了大量的configuration变化,上述和似乎没有工作,redirect是更复杂的开始,但我已经减less到其基本forms只是为了得到正确的语法,我仍然失败… 在我引用的许多网页中,这是一个 – https://www.nginx.com/blog/creating-nginx-rewrite-rules/ server { listen 80; root /usr/share/nginx/html; access_log /var/log/nginx/root_host.access.log main; error_log /var/log/nginx/root_host.error.log; location /area1/ { rewrite /area1/(.*)$ / break; } if (!-e $request_filename) { rewrite /wp-admin$ $scheme://$host$uri/ permanent; rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) […]

Nginx HTTP Proxying位置之间的链接

假设我有一个域test.com。 和Nginx服务几个应用程序。 我能怎么做: test.com/match/here – 这将是请求 由nginx处理为: test.com/new/prefix/match/here 用nginx可以吗? #server context location /match/here { proxy_pass http://example.com/new/prefix; } location /app { … } . . . 另一个问题是如何一个位置可以通过nginxconfiguration只能redirect到另一个位置? 先谢谢你!

AWS中的负载平衡器和代理设置显示了不完整的性能

背景 最终用户发送给www.stuff.com/things的HTTP请求处理如下: 由负载平衡器(公共负载平衡器)负载平衡到NGINX逆向代理(我们称之为安全代理)。 安全代理将请求路由到专用应用程序负载均衡器。 专用负载均衡器根据URL路由stream量。 如果url是/things/…则请求被路由到另一个NGINX代理。 第二个NGINX代理(让我们称之为things代理)将所有请求路由到经典负载均衡器。 经典的负载均衡器侦听端口80和50000,并将请求平衡到托pipe应用程序的实例。 所以要回顾一下:我有公共负载平衡器 , 安全代理 , 私有负载平衡器 , things代理和经典负载平衡器。 问题 当用户试图访问www.stuff.com/things ,他们等待,他们等待,他们最终收到HTTP 504:网关超时。 或者,页面立即加载。 或者,一些元素快速加载而其他元素挂起。 debugging 我已经尝试从链中的几个地方发出请求: curl 经典的负载均衡器 ,响应是瞬间的 curl的things代理 ,反应是瞬间的 curl 私人负载均衡器 ,响应是即时的 curl 安全代理 ,响应是即时的 curl 公共负载平衡器 ,回应是slooooow …除非它是快速的 。 也许我需要重新configuration我的代理? 代理configuration things代理configuration如下: events { worker_connections 1024; } http { server { location ^~ /proxycheck { […]

忽略nginx服务器的error_pageconfiguration为一个特定的位置指令

我为我的服务器设置了静态错误页面,但是我想忽略那些以/api/开头的URL,因此那里的处理程序可以用非200代码响应,但不返回静态错误页面。 这里是现有的configuration: server { listen 80 default_server; listen [::]:80 default_server; server_name example.com; root /var/www/html/; index index.php; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_intercept_errors on; fastcgi_index app.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_read_timeout 600; } error_page 404 /error/404.html; error_page 500 502 503 504 /error/50x.html; […]

为NGINX代理启用caching

我试图按照本教程cachingyt3.ggpht.com的请求。 我的configuration如下所示: proxy_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m inactive=60m; proxy_cache_key "$scheme$request_method$host$request_uri"; server { listen 80 default_server; location / { proxy_cache my_zone; add_header X-Proxy-Cache $upstream_cache_status; proxy_set_header Host $http_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; include proxy_params; proxy_pass https://yt3.ggpht.com; } } 如果我运行链接对我的本地服务器,yt3.ggpht.com返回: 在此服务器上未find请求的URL /-C9gaunpPNo8/VYGWj4xT-uI/AAAAAAAAAGo/pUPfpvLF7Dc/w2120-fcrop64=1-nd-c0xffffffff-rj-k-no/ 。 我们知道的就这些。 如果我删除proxy_set_header Host $http_host; 行,我的请求通过,但caching不起作用。 为什么不工作,如果我设置Host (它,如果我运行请求对另一个dummy-ngnix远程服务器)。 而且,为什么参数Host需要启用caching?

Nginx,Varnish 4.1后端抓取失败

我可以通过https和admin部分访问站点,但是不能访问非https / guest或任何应该caching的内容。 varnishadm -S /etc/varnish/secret -T localhost:6082 debug.health Connection failed (localhost:6082): (null) Varnishlog Begin bereq 2 fetch Timestamp Start: 1489151629.565881 0.000000 0.000000 BereqMethod GET BereqURL / BereqProtocol HTTP/1.1 BereqHeader Accept: text/html, application/xhtml+xml, image/jxr, */* BereqHeader AcceptLanguage: enGB BereqHeader UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393 BereqHeader Host: […]

使用nginx将真正的远程IP转发到代理服务器

为了隐藏我的网站IP,我用另一个VPS上的nginx代理了主服务器。 我想发送访问者真正的IP到我的网站,这里是我的conf.d文件夹中的configuration: proxy_cache_path /etc/nginx/cacheddata levels=1:2 keys_zone=staticfilecache:180m max_size=500m; proxy_temp_path /etc/nginx/cacheddata/temp; proxy_connect_timeout 30; proxy_read_timeout 120; proxy_send_timeout 120; #IMPORTANT – this sets the basic cache key that's used in the static file cache. proxy_cache_key "$scheme://$host$request_uri"; upstream wordpressapache { #The upstream apache server. You can have many of these and weight them accordingly, #allowing nginx to function as a […]

PHP 7.0 FPM – 等待可用套接字镶边

我的nginx + php 7.0 FPM有问题。 Chrome仍在阻止“等待可用插槽镶边”。 如果我重新启动PHP,我可以login到我的应用程序,并在“等待可用套接字铬”后。 我检查了/var/log/php7.0-fpm.log: [12-Mar-2017 20:48:29] NOTICE: fpm is running, pid 1088 [12-Mar-2017 20:48:29] NOTICE: ready to handle connections [12-Mar-2017 20:48:29] NOTICE: systemd monitor interval set to 10000ms [12-Mar-2017 21:15:52] NOTICE: fpm is running, pid 1121 [12-Mar-2017 21:15:52] NOTICE: ready to handle connections [12-Mar-2017 21:15:52] NOTICE: systemd monitor interval set to […]

nginxredirect基于$ request_uri

在我的默认站点configuration文件中,我有以下redirect来执行https: server { listen 80; server_name www.example.com example.com; return 301 https://example.com$request_uri; } 我想添加一个子域名,但redirect到一个参数的网站。 例如fr.example.com – > https://example.com?lang=fr 如果我做: return 301 https://example.com$request_uri&lang=fr; 它会在'&lang = fr'上添加$ request_uri中是否有其他参数。 我如何有条件地定义'?' 或'&',基于$ request_uri的内容? 我尝试了以下内容: server { listen 80; server_name fr.example.com; if ($request_uri ~ ""){ return 301 https://example.com?tlang=fr; } return 301 https://example.com$request_uri&tlang=fr; } 但是像这样这个网站一起失败了。 谢谢