Articles of nginx

nginx 1.7.9:反向代理Web套接字:挂起服务停止/服务重新启动,从不退出

我们使用nginx对一对websocket服务器进行负载均衡,并遇到了问题。 一旦将stream量实际连接到Web套接字服务器,它将不会优雅地退出或closures。 比如service nginx stop,或者nginx -s quit或者nginx -s reload会导致一个或者多个工作进程永远报告“worker process is shutting down”。 stream程是: 用下面的configuration启动nginx。 将stream量传递给nginx端点(即使使用networking浏览器打到443端口并获得404错误就足够了) 使用服务控制或发送退出命令 nginx现在挂起来了。 我们在centos v6上运行nginx 我们的编译选项和高级configuration的细节: [root@nginx1 nginx]# nginx -V nginx version: nginx/1.7.9 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) TLS SNI support enabled configure arguments: –user=nginx –group=nginx –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –with-http_gzip_static_module –with-http_ssl_module –add-module=/opt/nginx_upstream_check_module-master/ […]

全局禁用Nginx中所有站点的静态内容访问日志logging

我试图全局禁用access_log和log_not_found所有静态内容和所有运行在同一个nginx实例上的虚拟主机。 为了pipe理服务器块中的全局设置,我在每个虚拟主机的服务器块中都包含一个global/restrictions.conf 。 虚拟主机的configuration如下所示: server { listen 1.2.3.4:80; server_name domain.com *.domain.com; access_log /var/domains/domain.com-access.log combined; error_log /var/domains/domain.com-error.log error; root /var/www/domain.com/; location / { index index.php index.html index.htm; try_files $uri $uri/ @rewrites; } location @rewrites { rewrite ^ /index.php last; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/domain.com-php-fpm.socket; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; […]

在stderr中发送FastCGI:无法打开主脚本

情况: 服务器A和服务器B安装了相同的Ubuntu 14.04,相同的nginx版本(1.4.6),相同的虚拟主机(domain.com)和joomla文件夹(rsync-ed从服务器A到B) 但服务器A只能显示其首页,并会在任何菜单项上显示“没有指定文件input”。 如果我在/ etc / hosts中更改,以便服务器A的IP在服务器Btesting后使用domain.com,则不会立即失败。 只有几分钟后,才会​​出现错误。 在nginx的错误日志中有几条消息,如下所示: 2015/02/23 12:01:57 [error] 15515#0: *260609 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined property: JPagination::$pagesTotal in /var/www/joomla/templates/ashton/html/com_content/featured/default.php on line 76" while reading response header from upstream, client: 10.224.202.152, server: www.domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.domain.com"

在Jetty 9上https到http反向代理

好吧,基本上我想要做的就是设置一个反向代理服务器,在nginx上提供https页面,并使用http将它们redirect到Jetty。 问题是,一旦servlet发现它被发送到http页面,实际上需要https并redirect到https地址。 以前,我已经在Jetty 7下运行了所有代码: <Set name="forwarded">true</Set> 到Jetty.xml的SelectChannelConnector,现在,我决定升级到Jetty 9我似乎无法find任何替代这个configuration,我敢肯定有没有问题,我的nginx设置,因为它用Jetty工作得很好7。 这里是我的nginxconfiguration的一部分,只是为了使事情更清晰: location / { proxy_pass http://127.0.0.1:8080; include /etc/nginx/proxy_params; } 虽然这是我的proxy_params文件: proxy_redirect off; proxy_set_header Host $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;

NGINX,如何去掉$ fastcgi_script_name中的位置前缀

我已经读过: 如何从nginxconfiguration$ uri中删除位置块? 但有没有一种方法来剥离位置块的前缀从$ fastcgi_script_name不使用正则expression式? 例如 : location /foo/ { access_log /var/log/nginx/access-truc.log FOO; alias /srv/http/php; fastcgi_pass fpm; fastcgi_index index.php; include fastcgi.conf; } (注意:FOO是显示$ fastcgi_script_name的日志格式) fastcgi.conf有这一行: fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 我希望将$fastcgi_script_name设置为只有bar.php而不是foo/bar.php的url http://example.com/foo/bar.php

NGINX负载平衡不能按预期工作

我有一个作为负载平衡器的Ubuntu系统, /etc/nginx/sites-available/default如下所示: http { upstream myapp1 { server 192.168.0.20:80; } server { listen 80; location / { proxy_pass http://myapp1; } } } 在IP地址为192.168.0.20的设备上,我设置了一个命令来监听所有的80端口连接 sudo tcpdump -n -tttt -i eth0 port 80 但是当通过端口80访问负载均衡器时, 192.168.0.20没有任何提示,为什么会发生这种情况呢? 而192.168.0.20的/etc/nginx/sites-available/default : server { listen 80 default_server; #listen [::]:80 default_server ipv6only=on; root /var/www; index index.php index.html index.htm; server_name 192.168.0.20; location / { […]

NGINXcaching错误:在/etc/nginx/nginx.conf中与已声明的大小0冲突

我目前的Drupalconfigurationnginx提供以下错误。 不知何故,我无法启用nginxcaching。 试过不同的configuration,但超时我得到相同的错误。 任何人都可以帮忙吗? nginx: [emerg] the size 5242880 of shared memory zone "MYAPP" conflicts with already declared size 0 in /etc/nginx/nginx.conf:51 nginx: configuration file /etc/nginx/nginx.conf test failed 我的nginx.conf user nginx; worker_processes auto; http { include /etc/nginx/conf.d/*.conf; include /etc/nginx/mime.types; fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=MYAPP:5M max_size=256M inactive=2h; fastcgi_cache_key “$scheme$request_method$host$request_uri”; add_header X-Cache $upstream_cache_status; ## Set a cache_uid variable […]

以这两种方式设置环境variables有什么区别?

对于我正在开发的一个项目,我们需要nginx和lua,我们就这样开始: MYVAR1=some_value MYVAR2=some_value /usr/local/openresty/nginx/sbin/nginx -p `pwd`/ -c nginx.conf 一切正常。 相反,如果我们这样做: export MYVAR1=some_value export MYVAR2=some_value /usr/local/openresty/nginx/sbin/nginx -p `pwd`/ -c nginx.conf 然后,在工作进程内运行的lua脚本抱怨MYVAR1和MYVAR2没有设置。 这两者有什么区别,为什么在第二版中nginx + lua没有选中呢?

有没有办法获得Nginx的proxy_cache过期时间?

这是我的nginx proxy_cacheconfiguration: proxy_cache cache_one; location ~ \.(jpg|png|gif) { proxy_cache_valid 1d; } 它的工作,但我永远不知道图像到期时间 我想为这样的过期时间添加一个标题: location ~ \.(jpg|png|gif) { proxy_cache_valid 1d; add_header expires $proxy_cache_expires; } 这可能吗? 我怎样才能得到$proxy_cache_expires ?

Kibana4 + nginx反向代理使用位置/ kibana4 / =未find404

我试图用nginx反向代理来设置Kibana4 ,目前已经取得了部分成功。 这是我的configuration相关的Kibana: server { listen 82; server_name ${HOSTNAME}; set $kibana kibana.docker; location /kibana4/ { proxy_pass http://$kibana:5601; proxy_set_header Host $host; proxy_set_header Referer ""; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_connect_timeout 150; proxy_send_timeout 100; proxy_read_timeout 100; proxy_buffers 16 64k; proxy_busy_buffers_size 64k; client_max_body_size 256k; client_body_buffer_size 128k; } } 在这种情况下,如果我去http://localhost:82/kibana4/我会得到未发现404 但是如果我用location /kibana4/replacelocation /kibana4/ ,那么一切正常 – 当然在这种情况下,URL变为http://localhost:82 […]