Articles of nginx

testing是否设置了nginxvariables

如果它尚未设置,我需要将一个variables设置为默认值。 以下configuration完成这项工作: if ($foo ~ "^$") { set $foo default-value; } 但它会产生运行时警告: 使用未初始化的“foo”variables 有没有一种方法来testing是否设置了一个variables,而不会产生警告,也没有closures全局警告: uninitialized_variable_warn off;

nginx:有多个服务器指令的上游?

我试图打包使用nginx作为代理的2个应用程序,并将每个configuration文件传递到/etc/nginx/conf.d/ 。 在一个文件( combined.conf )中做这个很好: upstream backend1 { http://localhost:8989; } upstream backend2 { http://localhost:8990; } server { location /backend1/ { proxy_pass http://backend1; } location /backend2/ { proxy_pass http://backend2; } 但是,当分成两个文件时,其中一个redirect系统失败: backend1.conf : upstream backend1 { http://localhost:8989; } server { location /backend1/ { proxy_pass http://backend1; } backend2.conf : upstream backend2 { http://localhost:8990; } server { location […]

nginx重写或内部redirect周期

我试图找出我的nginxconfiguration中导致redirect循环时试图访问不存在的URLconfiguration如下: server { listen 127.0.0.1:8080; server_name .somedomain.com; root /var/www/somedomain.com; access_log /var/log/nginx/somedomain.com-access.nginx.log; error_log /var/log/nginx/somedomain.com-error.nginx.log debug; location ~* \.php.$ { # Proxy all requests with an URI ending with .php* # (includes PHP, PHP3, PHP4, PHP5…) include /etc/nginx/fastcgi.conf; } # all other files location / { root /var/www/somedomain.com; try_files $uri $uri/ ; } error_page 404 /errors/404.html; location […]

nginx在65k字节后终止连接

我已经将nginxconfiguration为在gunicorn下运行的Python应用程序的前端,但nginx在大约65k的数据发送之后正在终止连接。 例如,我有一个看起来像这样的视图: def debug_big_file(request): return HttpResponse("x" * 500000) 但是当我通过nginx访问这个URL时,我只得到了65283个字节: $ curl https://example.com/debug/big-file | wc … curl: (18) transfer closed with outstanding read data remaining 0 1 65283 请注意,当直接访问gunicorn时,一切都按预期运行: $ curl http://localhost:1234/debug/big-file | wc … 0 1 500000 相关的nginxconfiguration: location / { proxy_pass http://localhost:1234/; proxy_redirect off; proxy_headers_hash_bucket_size 96; } 和nginx版本1.7.0 其他一些事实: 从请求到请求的字节数是一致的,但是根据内容而不同(我首先注意到它有一个大的PNG文件,在65,372字节之后被截断,而不是65,283) 正确发送110k字节(即"x" * 110000返回全部110,000字节),但是120k字节不正确 tcpdump表明nginx正在向gunicorn发送一个RST数据包:

当configurationuserdir时,nginx fastcgi“主脚本未知”

我讨厌configurationnginx。 这太复杂了 我如何让PHP在我的用户目录中工作? 这里是我的nginx.conf的相关部分: location ~ ^/~(.+?)(/.*)?$ { autoindex on; autoindex_exact_size off; alias /home/$1/public_html$2; location ~ \.php { include /etc/nginx/fastcgi.conf; fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; } } 这给了我错误: FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream在nginx错误日志中FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream 。 […]

Nginx启动失败ssl没有这样的文件或目录

这是我得到的错误: 重新加载nginxconfiguration:nginx:[emerg] SSL_CTX_use_certificate_chain_file(“/ path / to / cert.pem”)failed(SSL:error:02001002:system library:fopen:No such file or directory error:20074002:BIO routines:FILE_CTRL:system lib错误:140DC002:SSL例程:SSL_CTX_use_certificate_chain_file:系统库)nginx:configuration文件/etc/nginx/nginx.conftesting失败 我100%确定该文件位于该位置,但Nginx似乎认为它不在那里。 我按顺序手动合并了domain.crt和intermediate.crt 。 我一整天都在摸索这个问题。 我希望有人看到这个错误,并有一个解决scheme(并注意这不是一个粘贴错误的文件位置只显示一次,而不是在'没有这样的文件或目录后')。

使用NGINX代理HTTPS请求HTTP后端

我有nginx被configuration为我的外部可见的networking服务器,通过HTTP与后端通话。 我想要实现的场景是: 客户端向nginx发送HTTP请求,nginx将通过HTTPSredirect到相同的URL nginx代理请求通过HTTP到后端 nginx通过HTTP接收来自后端的响应。 nginx通过HTTPS将其传递回客户端 我当前的configuration(后端configuration正确)是: 服务器{ 听80; server_name localhost; 位置〜。* { proxy_pass http://后端; proxy_redirect http://后端https:// $ host; proxy_set_header主机$主机; } } 我的问题是对客户端(步骤4)的响应是通过HTTP而不是HTTPS发送的。 有任何想法吗?

如何设置nginx的默认主机?

我想弄清楚如何为我的nginx安装设置一个默认的主机。 我在nginx Wiki中发现了这篇文章: http://wiki.nginx.org/NginxVirtualHostExample#A_Default_Catchall_Virtual_Host 不幸的是,这是行不通的。 重新启动后,我得到这个: Restarting nginx: nginx: [emerg] unknown directive "http" in /etc/nginx/sites-enabled/catchall:1 nginx: configuration file /etc/nginx/nginx.conf test failed 删除http指令后,我得到这个: Restarting nginx: nginx: [emerg] unknown log format "main" in /etc/nginx/sites-enabled/catchall:7 nginx: configuration file /etc/nginx/nginx.conf test failed 我在Ubuntu 10.04.3上使用官方的nginx PPA。 nginx版本1.0.9正在运行。

在Nginx中禁用某些path的SSL

我有一个网站,我希望所有的请求都使用HTTPS完成,除了请求以/foo/开头的path的URL。 如何在Nginx中configuration? 现在我用SSL运行所有请求: server { listen 443; ssl on; ssl_certificate /home/admin/ssl/ssl.crt; ssl_certificate_key /home/admin/ssl/ssl.key; server_name www.mydomain.com; location / { proxy_pass http://localhost:8000; … } }

Nginx将日志条目转换为多个文件

我想logging相同的access.log条目来分隔文件,所以当请求进来时,它应该填充a.log和b.log。 有没有办法用nginx做到这一点?