Articles of nginx

nginx优先考虑外部位置块的嵌套位置

有人可以解释为什么这不按照人们所期望的方式工作吗? 在下面的nginxconfiguration中,假设第一个nginx将使用正则expression式匹配的图像扩展块,只有在之后才会进入内部块,其中^~优先于其他所有内容。 看起来nginx正在查看更大的图片而不考虑范围,并匹配像/images/something.png类的请求的外部正则expression式扩展块之前的^~ /images ? location ~* \.(css|js|jpg|png|gif|ico)$ { expires 7d; add_header Image-By-Extension 1; } location / { location ^~ /images { add_header Image-By-Folder 1; … } }

使用Nginx位置configurationredirect到HTTPS和Apex域

我想通过使用位置块的nginxconfiguration在我的应用程序中强制HTTPS和apex域名(例如https://example.com )。 我目前有以下nginx_app.conf文件(它与apex和www子域以及http和https一起工作): location / { try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /app.php/$1 last; } location ~ ^/(app|config)\.php(/|$) { # fastcgi_pass directives go here… } 为了强制apex域和https,我尝试使用if语句,如下所示,检查$ scheme和$ hostvariables,但是出现一个页面没有正确redirect的错误。 我还添加了一个HSTS指令 。 location / { if ($scheme = http) { rewrite ^/(.*) https://$host/$1 permanent; } if ($host = www.example.com) { rewrite ^/(.*) https://example.com/$1 permanent; […]

如何将访问日志与同一服务器的两个不同域的请求分开?

我的nginxconfiguration如下所示: server { listen 80; server_name domain1.com domain2.com; access_log /var/log/myapp/nginx/access.log; … } 目前,来自两个域的请求都被logging到同一个文件中,我想将它们分开,以便来自domain1.com请求继续保存在access.log ,而来自domain2.com请求保存在domain2.access.log 。 我怎样才能做到这一点?

Nginx作为本地networking的代理服务器

我目前使用squid作为本地networking的代理服务器,但我并不完全满意。 Nginx是否也适合用作本地networking上的代理服务器? 它是否被积极地用于这个目的?

在Nginx中重写不适用于POST请求

我有两个VPS(一个用于故障转移),都运行Nginx作为后端服务器的负载平衡器。 另外,我已经在Nginx上为我的域(在GoDaddy.com上注册)启用并configuration了SSL。 由于我正在使用DNS Alogging来configurationVPS故障转移的域,因此我无法input端口号(只允许IP号码)。因此,默认情况下域名ping端口80.但ssl侦听端口443。 为此,我在nginx的服务器块中使用rewrite方法,但不适用于POST请求。 虽然它适用于GET请求。 我知道proxy_pass可以与POST请求一起使用,但这不是正确的做法(不安全)。 我应该直接在HTTPS连接上发布请求。 这里是我的nginx conf: upstream tomcat_servers{ least_conn; server 123.45.678.90:8080; server 124.345.78.23:8180; } server { listen 80; server_name thedomain.com; rewrite ^(.*) https://$host$request_uri? permanent; } server { listen 443; server_name thedomain.com; ….ssl config….. location / { proxy_pass http://tomcat_servers; proxy_http_version 1.1; proxy_connect_timeout 30s; proxy_read_timeout 30s; proxy_send_timeout 30s; proxy_next_upstream timeout; proxy_next_upstream error invalid_header […]

不能将NGinx版本存储到variables

这似乎是一个愚蠢的问题,但我似乎无法将nginx -v输出存储到一个variables,甚至写在bash中的文件。 php –version和mysql –version似乎工作正常,但Nginx不会保存。 有没有办法做到这一点。 我在尝试: NGINX_VERSION=$(nginx -v) nginx -v > /home/user/nginxversion.txt PHP以相同的方式正常工作,但nginx不会保存。 PHP_VERSION=$(php –version) php -v > /home/user/phpversion.txt

发送LAN​​上运行的Nginxcaching所需的“X-Real-IP”和“X-Forwarded-For”?

我将Nginx设置为一个cachingHTTP服务器,用于在我的LAN上进行Steam和Origin游戏下载。 如果出现以下情况,Nginx是否需要将X-Real-IP和X-Forwarded-For标头发送到服务器: IP地址将始终是RFC1918地址(192.168,172.16,10) 没有状态需要被上游内容服务器跟踪 如果不太可能导致问题,我想禁用发送这些头来保存less量的带宽。 非常感谢

限制NGINX上的子域访问

我有一个域,它叫做mydomain.com ,它运行在NGINX服务器上。 我在为subdomain.mydomain.com sites-enabled上添加了新的configuration,并且工作。 但是当我访问, whatever.mydomain.com , wildcard.mydomain.com ,NGINX不显示404,但它是像mydomain.com执行configuration。 如何限制访问子域名,仅适用于启用网站的可用configuration?

为什么Chrome浏览器不能识别我的nginx http2服务器?

我设置我的Nginx的conf 数字海洋纸 ,现在http2可用… 但在Chrome(版本54.0.2840.98(64位))开发工具,它始终在HTTP 1/1: NAME METHOD STATUS PROTOCOL shell.js?v=xx.. GET 200 http/1.1 我的服务器运行Ubuntu 16.04 LTS,它同时支持ALPN和NPN,并且随附的openssl版本是1.0.2g 我检查了这个工具网站的 http2支持,结果是: Yeah! example.com supports HTTP/2.0. ALPN supported… 也检查curl是好的 $ curl -I –http2 https://www.example.com HTTP/2 200 server: nginx/1.10.0 (Ubuntu) date: Tue, 13 Dec 2016 15:59:13 GMT content-type: text/html; charset=utf-8 content-length: 5603 x-powered-by: Express cache-control: public, max-age=0 etag: W/"15e3-EUyjnNnyevoQO+tRlVVZxg" vary: […]

NGINX托pipe域的默认redirect

我试图将所有没有服务器指令的托pipe域redirect到位于公司域服务器指令内的停放页面。 目前,我有以下的只能redirect到主页,因为转发NON-TLS公司域请求也需要相同的指令。 server { listen 80 default_server; listen [::]:80 default_server; server_name _; return 301 https://company.com$request_uri; } 我需要一个服务器指令,将所有不是company.com的请求转发到company.com/parked.php