Articles of nginx

Node.js Express NGINX:静态文件path与名称间隔的proxy_pass断开

所以我正在访问我的服务器在domain.com:3333但只是把它切换到domain.com/nodeapp使用上游和代理传递在我的nginxconfiguration。 redirect工作得很好,但现在链接到我的index.html(/styles/style.css&socket.io/socket.io.ks)使用的静态文件被打破,所有显示的是原始的HTML。 从index.js app.get('/nodeapp', function(req,res){ res.sendFile(path.join(__dirname, '/views', 'index.html')); }); app.use('/styles', express.static(path.join(__dirname, '/views/styles'))); 从index.html <link rel="stylesheet" type="text/css" href="styles/style.css"> <script src="socket.io/socket.io.js"></script> 从… / nginx / sites-enabled / default upstream nodeapp{ server localhost:3333 fail_timeout=0; } server{ …. location /nodeapp{ proxy_pass http://nodeapp; } …. } 我如何重新build立链接? 请注意,在我的index.js切换之前,显示的第一行是app.get('/', function(req,res){

如何升级生产服务器中的ngx_pagespeed?

我在CentOS 7中有一个LEMP设置。我打算安装ngx_pagespeed模块。 当我阅读文档时,我意识到,与Apache不同的是,我不能用Nginxdynamic地安装这个模块。 所以从我的理解,我现在需要卸载当前的Nginx,用ngx_pagespeed编译Nginx并重新安装这个编译版本。 这就是我的下一个问题: 如果将来需要升级Nginx或ngx_pagespeed模块会发生什么情况,而且我已经有了一个使用ngx_pagespeed的生产性LEMP服务器? 然后我需要做同样的事情,即首先卸载Nginx + ngx_pagespeed,编译模块&nginx的最新版本并重新安装新版本? 这似乎是一个很大的麻烦。 Isint有一个更好或更简单的方法来做到这一点?

用NGINX保护REST API

嗨,我有一个背后的NGINX API。 该API被configuration为要求对所有操作进行身份validation。 我想在它前面有一个NGINX代理来传递一些动作的authentication参数,这样他们就可以在没有authentication的情况下被访问。 身份validation在主要位置上工作正常,但是当我尝试在NGXINX位置指定特定path时,它仍然提示我input凭据。 这里重要的是,我想要允许的唯一行动是STATUS。 其他的一切都不应该被第二个地点拾起。 有没有办法做到这一点没有PCRE或正则expression式匹配? location / { add_header 'Access-Control-Allow-Origin' *; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Headers' 'Content-Type,Accept'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header X-Proxy-Cache $upstream_cache_status; proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; proxy_hide_header Cache-Control; proxy_hide_header Set-Cookie; proxy_pass http://backend; add_header 'Location1' '1'; location /1/2/3?action=STATUS { add_header 'Location2' '2'; proxy_set_header Authorization "Basic BLAHBLAHBLAH"; proxy_pass http://backend; } […]

“nginx没有运行” – 但实际上是

运行Ubuntu Server 14.04.1 LTS 检查nginx状态说它没有运行: $ sudo service nginx status * nginx is not running 但是,正如它所支持的网站正在运作一样,并且: 过程存在: $ ps aux | grep nginx root 1445 0.0 0.2 86008 1448 ? Ss 18:06 0:00 nginx: master process /usr/sbin/nginx www-data 1446 0.0 0.3 86320 1868 ? S 18:06 0:00 nginx: worker process www-data 1447 0.0 0.3 86320 […]

nginx – 没有redirect的代理传递

我在AngularJS有一个网站。 网站使用hashbang模式,我目前有prerendering的情况。 我的网站有这样的URL: http://www.watchawearin.com/#!/item/511 : http://www.watchawearin.com/api/ !/item/511,我有一个后端的URL: http://www.watchawearin.com/api/ : http://www.watchawearin.com/api/ 。 现在,当Facebook访问上面的URL,它变成: http://www.watchawearin.com/?_escaped_fragment_=/item/511 ://www.watchawearin.com/?_escaped_fragment_=/item/511这是好的,我有一个像这样的nginx的configuration: if ($prerender = 1) { rewrite .* /api/prerender break; proxy_pass $scheme://www.watchawearin.com; } Facebook提取预渲染的页面,但被redirect到: http://www.watchawearin.com/api/prerender/?_escaped_fragment_=%2Fitem%2F511 ://www.watchawearin.com/api/prerender/?_escaped_fragment_ http://www.watchawearin.com/api/prerender/?_escaped_fragment_=%2Fitem%2F511 2Fitem%2F511。 我可以实现服务的分段的页面,但没有redirect?

Docker和nginx上游零停机

我有一些奇怪的问题试图使用nginx的上游指令自动化Docker容器的部署。 出于某种原因,当我手动做下面的工作,但是当我尝试自动化它,我没有得到一致的结果。 基本上我把最新的图像停止,删除2个正在运行的容器中的1个然后启动容器然后更新nginx上游conf文件重新加载nginxconfiguration。 重复第二个容器。 看起来很简单,但由于某种原因,我可以“让这个工作在一个bash脚本所有的时间。 我正在使用seige来加载testing应用程序。 siege -d1 -t75S -c25 http://192.168.49.4:8087 我的脚本自动化部署运行脚本之前,最新的图像被拉。 #! /bin/bash appname=appnamexyz; appport=8000; host_ip=192.168.49.4; registry=192.168.254.96; echo "upstream api_servers {${nl} server $(docker port ${appname}-1 ${appport}) max_fails=2 fail_timeout=1s;${nl} server $(docker port ${appname}-2 ${appport}) max_fails=2 fail_timeout=1s;${nl} }" > /etc/nginx/conf.d/api_upstream.conf sed -i "s/server $(docker port $appname-1 $appport)/server xxx/g" /etc/nginx/conf.d/api_upstream.conf docker stop $appname-1 docker rm -f $appname-1 […]

带有多个ssl域的Nginx反向代理

当我需要将它configuration为基于源服务器的多个位置的反向代理时,我在Nginx中遇到问题,但在一个端口上。 例如,我有这些服务器: server1.domain.com server2.domain.com server3.domain.com nginx.domain.com是Nginx反向代理服务器 我需要通过这个scheme访问: nginx.domain.com/site -> server1.domain.com/site (https) nginx.domain.com/site2 -> (https) server2.domain.com/site2 (https) nginx.domain.com/site3 -> (https) server3.domain.com/site3 但是现在我只能访问configuration中第一个的site2。 当我改变命令,然后是工作site3。 所有服务器的位置configuration都可以。 我的default.conf我有以下configuration。 服务器1 server { listen 80; server_name server1.domain.com; access_log off; error_log off; # some locations } 服务器2 server { listen 80; server_name server2.domain.com; access_log off; error_log off; # some locations } server […]

为什么我的Nginx位置规则不优先?

我在我的网站的根文件夹中有一个PHP应用程序(Wordpress),所有对网站的请求都很愉快地运行。 不过,我有一个子文件夹_links,我想用它来执行另一个不同的PHP脚本。 例如,如果用户访问site.com/_links/221312,则来自/ _links的index.php脚本将接pipe。 我以前使用一个.htaccess文件来实现这一点,但既然搬到nginx我不能让它工作。 这是旧的.htaccess文件。 RewriteEngine On RewriteRule ^([0-9]+)/?$ index.php?linkid=$1 [NC,L] 显然,我将URL的最后一位作为parameter passing给脚本。 这是我的nginxconfiguration。 请求例如site.com/_links/23423被if (!-e $request_filename) /index.php?q=/_links/23423 ,并被重写为/index.php?q=/_links/23423而不是被位置块拾取。 server { listen 127.0.0.1:8080; server_name site.com www.site.com m.site.com; root /var/www/site; location ^~ /_links/ { add_header location 1; root /var/www/site/_links; rewrite "^([0-9]+)/?$" /index.php?linkid=$1 break; location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param […]

Nginx负载平衡器最佳规格

我有3个Nginx服务器,每个服务器都应该处理大约2k个用户(并发连接)。 在他们面前我有Nginx负载均衡器。 这是4个虚拟机,共享相同的子网和相同的物理机器。 我想知道,我应该使用什么VM规格负载均衡器? 我没有负载平衡的经验,从来没有做过任何testing,所以当我知道我的应用服务器需要什么样的规格时,我不知道我应该使用什么样的nginx负载平衡器。 现在我正在考虑4核/ 4GB内存/ 4GB硬盘。 这对于负载均衡器来说足够了吗? Offtopic queston:是否有可能configurationMySQL,以便当一个MySQL数据库更新时,另一个。 有点像主/从configuration或类似的东西?

设置nginx进行访问控制的videostream

我正在尝试创build一个应用程序,它将在基于meteor / nodejs的学习环境中显示video。 问题是stream媒体本身。 正如许多页面所描述的,节点不适合用于静态内容。 所以我的想法是让我的nginx服务器为video服务。 问题是:这些video不应该是公开的,他们只能访问有权查看该video的login用户。 有没有办法configurationnginx让只有login到我的应用程序,并有权查看video查看video的用户? 什么是最好的方法?