Articles of nginx

try_files在这个nginxconfiguration中做了些什么?

设置基本的Nginx / PHP-FPMnetworking服务器时,我复制了这个configuration文件 server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; server_name server_domain_name_or_IP; location / { try_files $uri $uri/ =404; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 它工作,因为它应该,但我不明白如何try_files在location ~ \.php$ { …. }块服务请求的PHP文件,如domain.com/test.php 。 […]

当斜杠不在URI中时如何停止nginx 301自动redirect?

每当我在浏览器中尝试foobar.com/test时,nginx似乎都会将客户端redirect到(301)foobar.com/test/。 这种行为是不可接受的。 代理服务器是一个远程的Apache Web服务器。 我已经尝试了直接调用Apache服务器(没有代理),它不redirect客户端。 考虑到下面的nginx服务器configuration,任何想法我应该如何解决这个问题? server { listen 80; server_name fooBar.com; location /test { proxy_redirect off; proxy_pass http://1.1.1.1:80/; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-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; } location /test/ { proxy_redirect off; proxy_pass http://1.1.1.1:80/; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-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 […]

磁盘I / O和负载平均每小时高峰一次

我们已经把我们的服务器从Debian Wheezy更新到了Jessie,从php5.6更新到了php7.0,但是现在我们有一个磁盘I / O并且每小时准确地加载一次平均峰值。 确切的时间取决于系统的启动时间。 在这个服务器上,我们有: nginx的/ 1.10.1 PHP 7.0.8-1〜dotdeb + 8.1 Percona MySQL服务器5.6.30-76.3-log dovecot 2.2.devel 后缀2.11.3-1 java 1.7.0_101 我们试图返回到php5.6,禁用cron,禁用postfix和dovecot,停止我们的Java应用程序,但没有任何帮助。 峰值如下所示: iotop看起来如下所示: 我怎么能确切地知道是什么原因导致这些高峰,并消除它们?

Nginx的 – 重写和pass_proxy到另一个端口原因404找不到

试图让URL重写与端口转发工作,但似乎不起作用。 我的应用程序服务器运行在:8080端口,而nginx工作在默认的80 。 所以我不仅要重写url,还要把请求转发到另一个端口。 其实,我唯一想做的是通过它的快捷方式http://localhost/tom来查询现有资源http://localhost:8080/#/cat/tom ,而不需要任何redirect。 这是我基于nginx文档和其他问题所做的: server { listen 80; server_name localhost; root /; #charset koi8-r; #access_log logs/host.access.log main; location / { rewrite ^/([az]+)$ /#/cat/$1 break; proxy_pass http://localhost:8080; proxy_redirect off; } … } 已尝试其他configuration,但都没有工作。 当我访问http://localhost/tom它表示404 not found而http://localhost:8080/#/cat/tom按预期工作。 日志没有提到任何错误。 如何按预期强制这项工作?

proxy_set_header不工作

在/ etc / nginx的/网站可用/默认 server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; # Make site accessible from http://localhost/ server_name mywebsite.net; return 301 https://$host$request_uri; } server { listen 443; server_name localhost mywebsite.net; ssl on; ssl_certificate /etc/ssl/certs/odoo.crt; ssl_certificate_key /etc/ssl/private/odoo.key; ssl_session_timeout 5m; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; ssl_prefer_server_ciphers […]

什么导致nginx服务器上的这个错误 – 502坏的网关

我有一个在Nginx服务器上的Drupal 7中build立的网站。 每当我编辑任何内容并按保存,或者当我login到网站,或者当我改变一些configuration,我得到一个白屏幕与消息“502错误的网关”几次。 只有在login并保存更改时,才会向匿名访问者显示错误。 我做什么样的改变似乎并不重要。 我可以按下浏览器中的后退button,这会将我带回编辑屏幕,然后再次按保存,并成功保存更改。 这个错误今天上午在08:09再次发生,所以我看着PHP日志: 2016/10/20 08:09:00 [error] 20703#20703: *3297348 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 195.198.76.66, server: www.example.com, request: "POST /node/88/edit HTTP/1.1", upstream: "fastcgi://unix:/run/php/php-fpm.sock:", host: "www.example.com", referrer: "http://www.example.com/node/88/edit" 这是在同一时间的nginx日志: [20-Oct-2016 08:09:00] WARNING: [pool www0] child 10909, script '/srv/www/example/public_html/index.php' (request: "POST /index.php") execution timed out […]

在负载均衡器后面覆盖nginx中的$ scheme

我有一个负载均衡器后面的nginx服务器。 负载均衡器处理SSL终止,所有请求都在端口80上触发 nginx。我还使用SRCache模块使用Redis进行完整页面caching。 caching模块使用URL作为caching键,如$schemeGET$host$request_uri 。 我以为我可以重写Nginx的$schemevariables,所以caching密钥scheme将是https而不是http我不知道如何做,或者甚至可能。 我的应用程序caching各种事件后清除caching,它使用https生成caching键,但nginxcaching使用caching中的http键。 这意味着由于caching键名称不匹配,未正确清除caching。 这是我的网站configuration,如果有帮助: server { listen 80; server_name example.com example.org example.net ; set $redirect_to_https 0; if ( $http_x_forwarded_proto != 'https' ) { set $redirect_to_https 1; } if ( $request_uri = '/health-check.php' ) { set $redirect_to_https 0; } if ( $redirect_to_https = 1 ) { return 301 https://$host$request_uri; } # […]

将每个目录.htaccess(Apache)转换为Nginx

我的网站以前在Apache服务器上。 这是一个自定义的PHP网站,几乎每个文件夹都有.htaccess 。 我已经设法在主目录上的.htaccess一部分工作在Nginx,但我无法做到每个目录.htaccess指令。 以下是一些.htaccess文件: 主要.htaccess : RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^example.com RewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteRule ^search(.+)/$ search.php?search=$1 [L] RewriteRule ^search(.+)/page/(.+)/$ search.php?search=$1&page=$2 [L] RewriteRule ^nonton/(.+)/$ download.php?download=$1 [L] RewriteRule ^nonton/(.+)/(.+)/$ download.php?download=$1&size=$2 [L] RewriteRule ^get/(.+)/$ get_dl.php?dl=$1 [L] RewriteRule ^(.+)-live-streaming/$ tv.php?tv=$1 [L] RewriteRule ^thumb/(.+)$ data/thumb.php?i=$1 [L] RewriteRule ^sitemap.xml$ sitemap.php [L] Options -Indexes 按国家分类的URL: RewriteEngine On […]

nginx块curl和wget

我有nginxnetworking服务器。 我有一个丰富的内容网站,我发现一些恶意机器人正试图抓取我的内容。 我阻止任何curl或wget来这样的我的网站 如果($ http_user_agent〜*(curl | wget)){return 301 $ scheme://www.google.com/; } 但我发现我可以访问的内容,如果我改变了下面的curl请求中的用户代理 curl –user-agent“Googlebot / 2.1(+ http://www.google.com/bot.html)”http://example.com/mypage.php 要么 curl –user-agent“whatever”http://example.com/mypage.php 任何想法如何阻止使用Nginx的 curl或wget生成的任何请求,而不pipe已经发送的假的用户代理

WebDav重命名在Nginx后面安装的Apache mod_dav上失败

我正试图解决通过WebDav重命名文件的问题。 我们的堆栈由一台机器组成,通过Nginx,Varnish和Apache提供内容。 当您尝试重命名文件时,操作将失败,并显示当前正在使用的堆栈。 要连接到WebDav,客户端程序必须: 通过https:// host:443连接到NginX Nginx解开并转发请求到http:// localhost:81上的Varnish服务器 Varnish通过http:// localhost:82将请求转发给Apache,通过mod_dav提供会话 这里有一个失败的重命名的例子: $ cadaver https://webdav.domain/ Authentication required for Webdav on server `webdav.domain': Username: user Password: dav:/> cd sandbox dav:/sandbox/> mkdir test Creating `test': succeeded. dav:/sandbox/> ls Listing collection `/sandbox/': succeeded. Coll: test 0 Mar 12 16:00 dav:/sandbox/> move test newtest Moving `/sandbox/test' to `/sandbox/newtest': redirect to […]