Articles of nginx

质量301redirectURL与Nginx

我有一个600个url的列表。 由于系统的变化,url会变成新的格式。 我会列出旧的url和相应的新url。 但是,我如何301redirect所有这些? 例: /news/post-name -> /news/post-name.html /wordpress/στα-ελληνικά -> /wordpress/sta-ellinika.html (in greek) /cms/a-big-long-title-with-a-lot-of-te -> /cms/a-big-long-title-with-a-lot-of-text.html 没有可以使工作自动化的真正模式。 那么redirect所有这些方法的正确方法是什么?

如何使用nginx作为具有多个IP和SSL的反向代理?

我想设置nginx反向代理与多个域名和一个IP为他们每个人使用不同的SSL证书。 我运行Ubuntu作为安装在KVM / Qemu虚拟机上的操作系统。 据我了解nginx,它应该能够通过一个IP服务于一个域(和属于它的子域)。 但我不能让它运行… 这是我的nginxconfiguration: 在/ etc / nginx的/启用的站点 – / my_first_domain server { listen xxx84:80; # this is a public ip server_name firstdomain.com; access_log /var/log/nginx/access.log proxy; # I made my own logformat error_log /var/log/nginx/error.log; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Client-IP $remote_addr; proxy_set_header X-Host $host; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; location / { […]

Nginx通过PAMauthentication通过pam_script

有没有人设置这样的configuration? 这不适合我 我已经在Ubuntu 12.04上安装了nginx-extras(它是用PAM模块构build的),并添加到站点configuration中: location ^~ /restricted_place/ { auth_pam "Please specify login and password from main_site"; auth_pam_service_name "nginx"; } 之后,在/etc/pam.d/nginx : auth required pam_script.so dir=/path/to/my/auth_scripts 并写了最简单/path/to/my/auth_scripts/pam_script_auth (也试图编写复杂的脚本) #!/bin/sh exit 0 # should allow anyone 不起作用。 脚本启动(我写了全function的脚本,成功执行,检查凭据,写入自己的日志,并返回正确的退出代码,并执行明显长)。 但是没有访问权限,只有被拒绝。 在/var/log/nginx/error.log出现这一行: 2012/09/13 10:44:42 [alert] 1666#0: waitpid() failed (10: No child processes) 如果我在/etc/pam.d/nginx指定: auth required pam_unix.so 并授予www-data用户读取/etc/shadow权限,unix授权正常工作。 但脚本身份validation不起作用。 我不明白,麻烦在哪里。 […]

nginx $ uri被url解码

我使用nginx作为反向代理,我有2个规则,如: location ~ ^/indirect { rewrite ^/indirect(.*) /foobar$1; } location ~ ^/foobar { set $url http://example.com/something/index.php?var1=hello&access=$scheme://$host$uri; proxy_pass $url; } 所以,正如你所看到的,我将$urivariables作为parameter passing给代理页面( $urivariables是一个nginxvariables,请参阅http core module文档)。 问题是,如果我访问http://example.com/foobar/hello%20world $urivariables包含/foobar/hello world (正如你看到的, %20已经被它的url解码值,一个空格)。 然后,nginx在执行proxy_pass行(后端没有联系)之前返回http状态码400(坏请求)。 还有可用的$request_urivariables,它保存了客户端发出的原始请求URI,所以在这种情况下,它将保存正确的值,并使用%20序列。 但我不能使用这个,因为如果客户端通过/indirectpath, $request_uri将包含/indirect/…而我希望accessparameter passing给后端总是/foobar/… 有多个indirect类规则(这是一个DAV / calDAV / cardDAV服务器,有多个客户端连接到多个path,所以我需要这些indirect类规则),所以这是不可行的那里有proxy_pass ,有些客户直接进入/foobarpath。 那么有没有办法得到$uri没有url解码呢? 可能的事情是不可接受的: 发送请求双重编码,因为请求可能来自我无法控制的客户端 在eacy间接规则中以及在“直接”规则中多次指定最终的url,因为这会导致维护问题。

nginx:在重写的位置块中指定自定义标题

我正在尝试为nginx中的特定location块设置一些标头。 我遇到的问题是这些location块包含rewrite语句,显然这似乎删除自定义标头。 在这个例子中,我有两个规则: 里面的/static文件应该已经expires max; (其中设置头Cache-Control: max-age=some huge value和Expires: some future date really far off ),并将其名称被重写为不包含/static 其他地方的文件应该有Cache-Control: public (没有max-age ) 这是我尝试的configuration: server { listen [::]:80; root /somepath; location /static { expires max; rewrite /static(.*) /whatever$1; } add_header Cache-Control public; } 并具有以下目录结构: /somepath /somepath/f1.txt /somepath/static/f2.txt 然后我们得到以下内容: f1.txt : Cache-Control: public ,no Expires标题 f2.txt : Cache-Control: public […]

在制作链式证书时,是否应该包含根CA证书?

我正在使用Godaddy证书,通常我会连接证书,并成为一个链式证书 cat www.example.com.crt sf_bundle.crt > chained.cert 而在我的nginx.conf中, ssl_certificate chained.cert 在浏览器中,我看到如下链: www.example.com Starfield Secure Certification Authority Starfield Technologies Inc. 这很好,一切正常。 今天,我读了一篇博客文章CloudFlare [1],它说: The lowest hanging fruit in terms of reducing the size of these certificates was to remove the root certificates from the certificate bundle. There's no reason to include these since they should already be […]

由nginx工作进程导致的磁盘IO高得无法解决

我刚刚安装了一个Ubuntu 12.04.2 LTS服务器,服务于大量的非常大的静态文件。 configuration与其他机器上的configuration相同,效果很好。 另一台机器使用Ubuntu 11.10和nginx 1.0.5。 有问题的机器使用nginx 1.1.19,并且难以推动20MB / s左右(但在1Gbit专用线上),iotop显示nginx的高磁盘IO。 这是从iotop: TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 4569 be/4 www-data 754.61 K/s 0.00 B/s 0.00 % 99.99 % nginx: worker process 4571 be/4 www-data 1257.69 K/s 0.00 B/s 0.00 % 99.99 % nginx: worker process 4574 be/4 www-data 2.46 M/s […]

WordPress + nginx无限redirect循环

我有一个WordPress的网站进入pipe理区域的问题。 如果我input: http : //www.beshan.com/wp-admin/ 我得到一个无限的redirect循环,但如果我input: http://www.beshan.com/wp-admin/index.php 有用 我的客户端的服务器是一个centos linux + nginx nginx.conf: user www www; worker_processes 8; error_log logs/nginx_error.log crit; #pid /usr/local/webserver/nginx/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } http { include mime.types; default_type application/octet-stream; #charset gb2312; server_names_hash_bucket_size […]

在NGINX负载均衡器中保留响应头

我以这种方式将NGINX设置为两台Domino服务器的负载平衡器: http { upstream www.mydomain.com { server 1.1.1.1; server 2.2.2.2 backup; } server { listen 80; server_name www.mydomain.com; location / { proxy_pass http://www.mydomain.com; } } } 如果我直接访问Domino服务器,响应头是这样的: HTTP/1.1 200 OK Server: Lotus-Domino Date: Mon, 23 Dec 2013 12:19:36 GMT Last-Modified: Fri, 20 Dec 2013 08:16:27 GMT Content-Type: text/html; charset=US-ASCII Content-Length: 12713 Cache-control: private ETag: W/"MTAtODEwRC1DMjI1N0MzRDAwN0M3NTBCLUMyMjU3QzQ3MDAyRDczMzktMC1DTj1QYW51IEhhYXJhbW8vTz1BQUQ=" […]

Nginx的位置正则expression式不匹配

以下一直在为我cachingcss和js: location ~ "^(.*)\.(min.)?(css|js)$" { expires max; } 结果: $ curl -I http://mysite.com/test.css HTTP/1.1 200 OK Server: nginx Date: Thu, 16 Jan 2014 18:55:28 GMT Content-Type: text/css Content-Length: 19578 Last-Modified: Mon, 13 Jan 2014 18:54:53 GMT Connection: keep-alive Expires: Thu, 31 Dec 2037 23:55:55 GMT Cache-Control: max-age=315360000 X-Backend: stage01 Accept-Ranges: bytes 我正在尝试为我的js / css使用10位数的unix时间戳获取版本设置,并且遇到与下面的有效正则expression式匹配的正则expression式问题。 location […]