Articles of nginx

如何在Nginx中logging请求的开始时间

正如在这个答案中所述,Nginx的访问日志中的$ time_localvariables表示请求(或接近)的结束时间 。 那么,有没有办法在Nginx的访问日志中logging一个请求的开始时间呢? 我search了一下,但只是找不到任何引用来实现这一点。 来吧! 这不是一个非常简单的Web服务器function吗? 不要告诉我从$ time_local减去$ request_time …

nginx反向代理:缓冲区响应?

我正在为反向代理进行configuration,目的只是在两台上游服务器之间负载均衡请求,主要是为了在发生故障时进行冗余。 我很好奇这里描述的proxy_buffering的影响。 我是大型video文件的负载平衡请求,其中video的最大和最常见的“块”大约是2.5兆字节。 我们的CDN使用字节划分来请求这些video。 video文件比这个大得多。 proxy_buffering的默认值是已启用。 我的问题是: nginxcaching来自代理服务器的响应有什么好处? 它必须有一定的价值,如果(a)它是一个选项和(b)默认打开。 在我的情况下禁用它有意义吗? 请求的数据通常相当大?

从HAproxy的tcp连接logging客户端IP地址到nginx

如果互联网stream量通过SSL上的HAproxy负载均衡器传递给nginx Web服务器,那么如何logging客户端的IP地址? 我知道这样的方法: 我怎样才能使用HAproxy SSL和获得X-Forwarded-For头,并告诉PHP,SSL正在使用? 在请求到达HAproxy之前,您可以去掉ssl。 有没有反向login客户端IP地址,而无需剥离HAproxy之前的SSL? 我为http连接使用选项httpclose和选项forwardfor。 有没有这样的tcp连接相当于?

Nginx + Gunicorn + Django – nginx不允许使用静态文件

更新的代码 – 这仍然不工作。 Settings.py STATIC_ROOT = '/home/ubuntu/virtualenv/mysite/homelaunch/static/' STATIC_URL = '/static/' nginx conf :: / etc / nginx / sites-enabled / mysite server { server_name ec2-xxxx.compute-1.amazonaws.com; access_log /home/ubuntu/virtualenv/mysite/error/access.log; error_log /home/ubuntu/virtualenv/mysite/error/error.log warn; connection_pool_size 2048; location /static/ { #alias /home/ubuntu/virtualenv/mysite/homelaunch/static/; #alias /static/; root /home/ubuntu/virtualenv/mysite/homelaunch/; } location / { proxy_pass http://127.0.0.1:8001; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header X-Forwarded-Host […]

在将NGINX作为GAE的反向代理服务器时,出现错误的网关

我想使用NGINx作为反向代理服务器,所以我可以从中国大陆打开我的GAE(谷歌应用程序引擎)网站,因为大部分谷歌IP被GFW阻止。 DNS:我有这些DNSlogging: – A mydomain.com ==> xxxx CNAME www ==> ghs.google.com CNAME * ==> ghs.google.com 我打算使用地理DNS指向我的反向代理,以防万一来自中国大陆的请求,目前我通过将主机logging点mydomain.com本地进行本地testing。 我在Ubuntu 12.04上有nginx 1.1.19。 我的网站configuration文件是: server { #listen 80; listen 443 ssl; server_name mydomain.com; ssl on; ssl_certificate /home/user/Desktop/ssl/mydomain.com.pem; ssl_certificate_key /home/user/Desktop/ssl/mydomain.com.key; ssl_session_timeout 5m; ssl_protocols SSLv3 TLSv1; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP; ssl_prefer_server_ciphers on; large_client_header_buffers 4 16k; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; # keepalive_timeout 70; location […]

Nginx和js / css通过浏览器的caching进行版本控制

当js / css文件更新时,我想要轻松地清除浏览器的caching。 真实文件位置: /js/some-files.js /css/some-files.css 由浏览器调用的应用中设置的文件位置: /js/v1/some-files.js /css/v1/some-files.css 我尝试了以下,但去/js/v1/some-files.js给我404s 。 location ~ ^/(js|css)/v[0-9]+/(.*)$ { access_log off; expires 7d; add_header Cache-Control public; try_files $uri $uri/ $1/$2; } 你能发现我做错了吗?

GitLab别名为nginx

我已经在新鲜的Ubuntu 13.04服务器上安装GitLab 6.1,我希望有一个位置的GitLab服务 http://192.168.1.5/gitlab 我的/ etc / nginx / sites-available / default文件: upstream gitlab { server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; } server { listen 80; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; server_name localhost 192.168.1.5; server_tokens off; location /gitlab { alias /home/git/gitlab/public; try_files $uri $uri/index.html $uri.html @gitlab; } location @gitlab { proxy_read_timeout 300; proxy_connect_timeout 300; proxy_redirect […]

使用https和虚拟主机为nginx设置自定义错误页面

我们有一个作为负载均衡器的nginx(OpenResty 1.4.2.7)实例。 它有两个服务器指令,一个服务于一个特定的站点(让我们称之为www.our-special-host.com)和一个通配符。 我们正在尝试对其进行configuration,以便显示不同的502错误页面,具体取决于两个服务器伪指令的后端是closures的。 我们的configuration适用于HTTP,但不适用于HTTPS。 如果我们closures后端并打到www.our-special-host.com,我们会得到适当的HTTP和HTTPS错误。 但是,如果我们点击了其他托pipe站点,则会得到HTTP的正确错误页面,但对于HTTPS,我们会获得www.our-special-host.com的错误页面。 这里是我们的configuration(轻度编辑): server { server_name www.our-special-host.com listen 80; listen 443 ssl; error_page 502 /nginx_errors/loadbalancer_502_on_special_host.html; location /nginx_errors/ { alias /path/to/nginx_errors/; } location / { proxy_pass xxxx; … } ssl_certificate certificate.crt; ssl_certificate_key pk.key; } server { listen 80; listen 443 ssl; error_page 502 /nginx_errors/loadbalancer_502_on_other_hosts.html; location /nginx_errors/ { alias /path/to/nginx_errors/; } location […]

nginx – 获得parsing的server_name

我已经为我的网站创build了虚拟主机,然后我创build了一个名为server_name -> default_server的其他虚拟主机,以便在其他情况下显示特定的页面(例如,如果有人试图访问我的IP)。 我也使用phpmyadmin,roundcube和squirrelmail,我想redirect任何连接到他们从http到https。 这里是问题: 可以说我input:http: 44.44.44.44 (假设44.44.44.44是我的ip) 因为我已经设置了server_name -> default_server server { listen 80; server_name default_server; root /usr/share/nginx/www; index index.html index.htm; location /phpmyadmin { rewrite ^ https://$server_name$request_uri? permanent; } […] } 我redirect的url不是https://44.44.44.44/phpmyadmin但https://default_server/phpmyadmin哪个当然不存在。 所以我最终明确指出我的IP: location /phpmyadmin { rewrite ^ https://44.44.44.44$request_uri? permanent; } 它的工作原理是这样的,但我想知道是否有办法使用返回parsing的server_name或任何其他/更聪明的方式的variables做同样的事情。

Nginx重写为特定的目录

我不得不承认我对WebServers是全新的,现在试图弄清楚如何configuration我的nginx(用于家庭用途)。 我已经使用默认的结构在我的nginx上运行了web服务rutorrent。 现在我想改变目录结构为: /usr/share/nginx/html/ (should contain the default-config) /usr/share/nginx/rtorr_dir/ (should contain the rutorrent-content) 我的目标是:在我的浏览器中,我想input192.168.0.2/rutorrent ,这应该会自动访问rtorr_dir 。 我尝试了以下内容: server { listen *:80; access_log /var/log/nginx/access.log info; error_log /var/log/nginx/error.log debug; auth_basic "ruser"; auth_basic_user_file /etc/users.htpasswd; location /rutorrent { rewrite /rutorrent/(.*) /$1 break; root /usr/share/nginx/rtorr_dir; index index.php index.html; } location /RPC1 { include /etc/nginx/scgi_params; scgi_pass backend2; } location ~ \.php$ […]