Articles of nginx

如果代理目标不可用,Nginx本地回退错误页面

我通过Nginx服务器将请求转发到本地服务。 我现在尝试完成的是退回到本地错误页面,以防服务不可用。 我目前的configuration是 server { listen 80; server_name ""; location / { proxy_pass http://127.0.0.1:9080; 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_connect_timeout 1; proxy_next_upstream error timeout http_500 http_502 http_503 http_504 http_404; proxy_intercept_errors on; } error_page 501 502 503 @maintenance; location @maintenance { root /locust/www/fallback/htdocs; index index.html index.htm; } } 代理工作,但只要我使我的服务在9080不可用我的维修位置的index.html不显示。 任何build议这个configuration有什么问题?

Nginx:当nginx运行在supervisord下时,如何使用docker log collector

官方的nginx docker image( Dockerfile )使用以下技巧将其日志交给stdout和stderr,以便docker日志采集器捕获这些日志并使用docker logs <container-name> : # forward request and error logs to docker log collector RUN ln -sf /dev/stdout /var/log/nginx/access.log RUN ln -sf /dev/stderr /var/log/nginx/error.log 我想要做同样的事情,但是我在我的容器中拥有supervisord作为PID 1,它监督nginx进程并捕获stdout和stderr并将其放入它自己的日志文件中。 因此日志不能到达docker日志收集器。 这是我的supervisord.conf中的相关块 [program:nginx] command=/usr/sbin/nginx -g "daemon off;" priority=990 ; NOTE: We do not want to redirect stdout and stderr of a nginx process to a […]

为什么我的服务器不支持ALPN?

我目前正在运行一个使用NGINX 1.11.9和openssl 1.0.2g的Ubuntu 16.04.1 LTS服务器。 根据我读过的一切,这些版本应该支持ALPN,但是当我在KeyCDN的HTTP / 2testing工具上运行testing时,我得到“ALPN不被支持” 而当我执行echo | openssl s_client -alpn h2 -connect example.com:443 | grep ALPN echo | openssl s_client -alpn h2 -connect example.com:443 | grep ALPN echo | openssl s_client -alpn h2 -connect example.com:443 | grep ALPN ,我得到: depth=3 C = SE, O = AddTrust AB, OU = AddTrust External TTP […]

Nginx使用密码保护目录,除了特定的IP

在我的Nginx设置,我想密码保护一些网站,除非当我从家里访问我的IP。 我如何设置? 另外,除了访问我的家用电脑,这是安全的吗?

我将如何在同一台服务器上运行两个不同的Web服务器?

我知道你不能使用两个不同的服务器进程来监听相同的端口和IP,但显然这是可能的,如果你分配一个单独的IP地址给每个。 这是这种情况吗? 我正在考虑在同一台服务器上同时运行ningx和Apache(我也欢迎有关这是否是一个好主意的反馈),基本上是因为理想情况下我想尝试切换到nginx,但据说它的Tomcat支持不是很好,所以我想我需要保持这个Apache。 有没有人做过类似的事情? 这是build议,你怎么去呢?

使用nginx从URL中删除尾部的斜杠

我想在我的网站上的以下url是等效的: /foo/bar /foo/bar/ /foo/bar/index.html 进一步,我想第二个两个表格发出HTTP 301redirect到第一种forms。 我只是服务静态页面,并按照第三种forms进行排列。 (换句话说,当用户请求/foo/bar他们应该接收/usr/share/…/foo/bar/index.html文件)。 我的nginx.conf目前包含以下内容: rewrite ^(.+)/$ $1 permanent; index index.html; try_files $uri $uri/index.html =404; 这适用于/foo/bar/index.html请求,但是当我请求/foo/bar或/foo/bar/ Safari告诉我“发生了太多的redirect” – 我假设有一个无限的redirect循环或类似的东西。 我怎样才能让nginx以我描述的方式将URL映射到文件? 编辑:我的完整configuration 这是我的整个nginx.conf与我的域名replace“example.com”。 user www-data; worker_processes 1; pid /run/nginx.pid; events { worker_connections 768; } 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; include /etc/nginx/mime.types; […]

我可以对smtp,imap,pop3和http使用相同的SSL证书吗?

到目前为止,我正在使用自签名证书,但决定至less考虑获得“真实”的证书。 到目前为止,我注意到authentication的内部格式有点不同,那就是: http(nginx)证书只有CERTIFICATE部分(带有base64编码的内容)和KEY也只有base64的内容 smtp(exim)crt文件包含证书文本信息(发行者,主题,algorithm,date等等)以及带有base64数据的CERTIFICATE块,而exim的.key文件只包含base64编码密钥 imap / pop3(快递).pem文件包含密钥(base64),证书信息(文本)和证书本身(base64)。 我可以从thawte或这样的公司获得任何“networking”证书,并从这个(和密钥文件)生成所需的所有格式,我需要nginx,exim4和信使,还是我需要获得单独的证书,或者是什么其他完全吗?

如何检测ssl共享80/443 ssl nginx服务器configuration?

当nginx服务器被这样configuration时: server { listen 80; listen 443 ssl; server_name www.example.org; … } 如何通过HTTP或HTTPS检测到请求? (例如$http_port不可用,因为端口没有明确指定,因此它是空的)

Nginx与SPDY草案3,是可能的?

我目前正在使用SPDY模块的Nginx 1.4.1。 不幸的是,Nginx的SPDY模块只能用于协议草案2。 有没有办法使用Nginx,SPDY Draft 3?

为什么在NginX中添加Expire-Header到静态文件不起作用

我有一个单一的服务器块,我的网站驻留在该块内,我已经添加了一个location块,如下所示: server { … location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { expires 30d; add_header Pragma public; add_header Cache-Control "public"; } … } 当我用Y检查过期标题时! 缓慢没有任何东西被caching! 注意:在testing之前,我已经重新载入了我的configuration文件。 编辑1: 我注意到,更改任何静态文件都不会反映浏览器的新变化。 这个caching是否意味着服务器端caching? 我们不能在客户端浏览器上caching吗? 编辑2: HTTP/1.0 200 OK Server: nginx Date: Tue, 23 Sep 2014 07:41:20 GMT Content-Type: image/png Content-Length: 5597 Last-Modified: Wed, 30 Jul 2014 22:50:19 GMT ETag: "53d976ab-15dd" Accept-Ranges: bytes Age: […]