我在Nginx重写中遇到了一些麻烦。 我最近被博客移动到一个新的引擎,并且URL结构已经改变。 在我的旧博客引擎post位于一个forms为http://$host/yyyy/mm/title.html的URL上,但在新的引擎上,它们的格式为http://$host/yyyy/mm/title/ 。 服务器返回的实际文件位于/yyyy/mm/title/index.html 。 为了确保旧post中的链接仍然有效,我想在Nginx中进行重写,如下所示: rewrite ^/(\d\d\d\d)/(\d\d)/(.+)\.html$ $scheme://$host/$1/$2/$3/ permanent; 不幸的是,这会捕获以.html结尾的任何内容,包括index.html ,因此访问forms为/(\d\d\d\d/)/(\d\d)/(.+)/的url会导致redirect循环(nginx内部尝试使用/$1/$2/$3/index.html ,redirect到/$1/$2/$3/ ,redirect到index.html等)。 如果可能,我宁愿不使用if语句。 有任何想法吗? 为了参考该网站是静态的,我的服务器configuration看起来像这样(这里没有什么奇特的): server { listen [::]:80; server_name blog.samwhited.com; root /var/www/blog.samwhited.com; charset utf-8; location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } error_page 404 /error/404.html; error_page 403 /error/403.html; location /error/ { internal; } } 以下是预期redirect行为的一个简单示例: http://blog.samwhited.com/2008/09/test.html – > http://blog.samwhited.com/2008/08/test/ 如果可以隐藏index.html,那也是很好的。 […]
我使用nginx作为我现有的Web服务器上的反向代理。 我只想pipe理一组自定义错误页面,理想情况下在nginx内,因为这是最接近客户端的级别。 现在我可以使用error_pages和proxy_intercept_errors设置。 然而: 在400(错误请求)错误的情况下,我需要底层Web服务器能够通过一些JSON主体内容,详细说明为什么请求不好。 所以我需要一种proxy_intercept_errors 400个状态码禁用proxy_intercept_errors的方法。 对于任何状态码,我从不想显示默认的nginx错误页面。 现在从我所看到的,为了达到这个目的,我需要清楚地列出每个可能的状态代码,并且有一个错误页面呢? 例如,不要仅仅通配500以上的所有错误。 我的问题是 – 以上两个问题在nginx本身内是可以解决的吗? 如果没有,上述问题是否有明显的解决办法?
我正在开发一个远程https Web服务的应用程序。 在开发时,我需要从本地开发服务器(在ubuntu上运行nginx)到远程https web服务器的代理请求。 这里是相关的nginxconfiguration: server { server_name project.dev; listen 443; ssl on; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; location / { proxy_pass https://remote.server.com; proxy_set_header Host remote.server.com; proxy_redirect off; } } 问题是远程HTTPS服务器只能接受通过SSLv3的连接,如下面的openssl调用所示。 不工作: $ openssl s_client -connect remote.server.com:443 CONNECTED(00000003) 139849073899168:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:177: — no peer certificate available — No client certificate CA names sent — SSL […]
这是我的nginxconfiguration的一个片段: server { error_page 500 /errors/500.html; } 当我在我的应用程序中导致500人时,Chrome只显示默认的500页(Firefox和Safari显示空白页),而不是我的自定义错误页面。 我知道该文件存在,因为我可以访问http://server/errors/500.html ,我看到了页面。 我也可以将文件移动到文档根目录并将configuration更改为: server { error_page 500 /500.html; } 而nginx正确地为页面提供服务,所以在服务器上似乎没有其他的configuration。 我也试过: server { error_page 500 $document_root/errors/500.html; } 和: server { error_page 500 http://$http_host/errors/500.html; } 和: server { error_page 500 /500.html; location = /500.html { root /path/to/errors/; } } 没有运气。 这是预期的行为? 错误页面是否必须存在于文档根目录,还是我错过了一些明显的东西? 更新1:这也失败了: server { error_page 500 /foo.html; […]
在Apache中,如果1)我有多个虚拟主机侦听一个端口,2)如果没有请求匹配任何虚拟主机,则第一个虚拟主机将是应答请求的虚拟主机 。 例如,给我有这个configuration: <VirtualHost *:8080> ServerName www.fallbacksite.com:8080 ServerAlias *.fallbacksite.com # … </VirtualHost> <VirtualHost *:8080> ServerName www.specific-site.com:8080 ServerAlias *.specific-site.com # … </VirtualHost> 然后: 当某人specific-site.com:8080,那么第二个虚拟主机将会回答请求(这里并不令人意外) 当有人访问fallbacksite.com:8080时,那么第一个虚拟主机将回答请求(这里没有意外) 当有人访问hellohowareyou.com:8080(hellohowareyou.com指向服务器),那么第一个虚拟主机将回答请求 这是我试图用nginx实现的最后一个场景,但是在nginx.org网站上看不到任何关于这个的东西。 我尝试了过度渴望的通配符,但它抱怨说这是无效的。 你将如何在nginx中做上述configuration? 提前致谢!
我用: http { limit_req_zone $binary_remote_addr zone=one:10m rate=5r/s; } server { location ~ \.php$ { limit_req zone=one burst=2 nodelay; try_files $uri $uri/ /index.php; root /var/www/; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 我如何禁用IP的限制:127.0.0.1和99.99.99.99?
我在我的Nginx访问日志中遇到了一行: 218.201.121.99 – admin [12/Dec/2012:18:33:18 +0800] "GET /manager/html HTTP/1.1" 444 0 "-" "-" 让我强调这个IP只有一个logging。 注意已authentication的用户pipe理员 。 经过一些Googlesearch后,我只能发现这是经过身份validation的用户 ( http://wiki.nginx.org/HttpCoreModule#.24remote_user),Auth 基本模块 ( http:// wiki.nginx )对其进行了身份validation 。 org / HttpAuthBasicModule )。 但是,在我的网站(configuration)没有地方使用HTTP基本身份validation。 到底是怎么回事? 它是如何到达那里的? 用户是否被authentication?
我正在运行nginx和php-fpm,我想为每个主机设置jail。 我的设置有点复杂,所以在networking上的教程让我无处可去。 每个站点都有一个目录/var/www/domain.name/ 在这个目录里面,会有一个公共/目录,这个目录是网站的根目录,一个logging/目录,这个目录将专门存储该网站的nginx日志,以及chroot文件系统(etc /,usr /等等) 我碰到的第一个问题是,如何configuration它,PHP-FPM无法find通过nginx传递给它的文件。 他们导致“主脚本未知”错误,更糟糕的是,来自PHP-FPM的错误消息不再是冗长的,所以我无法弄清楚nginx传递的path。 主机的php-fpm池configuration如下所示: [host] user = host group = www-data chroot = /var/www/domain.name chdir = /public listen = 127.0.0.1:900x 每个池的“x”都是递增的。 这个主机的nginxconfiguration如下所示: server { listen 80; server_name domain.name *.domain.name; root /var/www/domain.name/public; index index.php index.html index.html; location ~ \.php$ { expires epoch; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; […]
我想允许在我的网站的一个特定的子域名上传1GB上传upload.xxx.xx.xx 。 目前我正在尝试类似于: server { if ( $host = 'upload.xxx.xx.xx' ) { client_max_body_size 1000M; } } 但是,当然,它给了我一个关于client_max_body_size不应该在那里的错误。 有没有办法做到我想要的东西,而不重复两个vhost ,否则所有的设置是相同的,或者在另一端,我应该不麻烦去确保用户只能上传大于10MB的麻烦upload子域名?
由于马克和他之前的回答更好地理解了我想实现的目标,所以我发布了一个(希望的)更清晰和略微不同的前一个问题的变体,因为这个线程已经达到饱和; 我试图在一个nginx服务器上运行多个WordPress站点,每个站点都需要不同版本的PHP。 我希望通过使用PHP-FPM的多个版本来实现这一点,每个版本都运行不同版本的PHP,与nginx分开。 然后,我想使用.conf文件来控制每个站点使用哪个PHP-FPM服务器,从而允许该站点在所需的PHP版本上运行。 (根据评论部分) 目前我的testsite1的服务器块是这样的,运行默认的PHP版本。 server { listen 80; listen [::]:80; root /usr/share/nginx/html/testsite1; index index.php index.html index.htm; server_name local.testsite1.com; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; […]