Articles of nginx

nginx反向代理在连接closures之前发送输出

我已经设置了一个反向代理与nginx webmin ..但它看起来像nginx之前不会发送HTTP响应连接closures后? 如果请求长请求(cronjob)请求结束后,输出将首先由最终用户接收? 如何设置nginx,以便在第一个字节被发送回代理(nginx)后立即发送响应? location / { proxy_pass https://xx.xx.xx.xx:10000/; }

启用PHP的Nginx通配符子域

我正在使用Laravel / PHP将Nginx设置为几个不同项目的临时服务器。 这个想法是在/var/www我将有不同数量的子目录,每个子目录都以subdomain.example.com格式访问。 考虑一下这个非常简单的Nginxconfiguration: server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; index index.html index.htm; server_name ~^(.*)\.example\.com$; root /var/www/$1; } 我有我的目录结构设置为: /var/www /subdomain1 /subdomain2 /subdomain3 如果我访问subdomain1.example.com , subdomain2.example.com或subdomain3.example.com则会提供相关子目录中的index.html文件。 迄今为止都是完美的。 当我尝试使用PHP文件工作时,问题出现了。 首先,我改变索引指令index index.php ,然后在server指令中添加以下内容: location ~ \.php$ { try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } […]

PHP的FPM,位置嵌套与unnested避免代码执行

有什么优势使用: location ~ \.php { location ~ \..*/.*\.php$ { return 403; } fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_intercept_errors on; } 相比 location ~ \..*/.*\.php$ { return 403; } location ~ \.php { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_intercept_errors on; } 我想避免在这里显示的任意代码执行: […]

Nginx的网站没有得到拾起

我的新网站没有被拿起。 我已经创build了appycontrol.staging : upstream appycontrol_staging { server unix:///var/www/appycontrol.staging/shared/sockets/puma.sock; } server { listen 80 default_server; server_name control-staging.somedomain.com; root /var/www/appycontrol.staging/current/public; location / { proxy_pass http://appycontrol_staging; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 我在已sites-enabled目录中添加了一个符号链接: [Staging] deploy@localhost:~$ ls -l /etc/nginx/sites-enabled/ total 0 lrwxrwxrwx 1 root root 45 Nov 3 2015 appyengine.staging -> /etc/nginx/sites-available/appyengine.staging lrwxrwxrwx 1 root root 46 […]

Nginx + Apache2 +让iPhoneencryption不能显示页面

我有nginx + letsencrypt SSL证书,它的工作正常,除了新的iOS与Safari。 它适用于iPhone 4,但与iPhone 5和更新不是。 我在nginx日志中看到了多个请求: IPADDRESS – – [03/Dec/2016:10:08:08 +0000] "GET / HTTP/2.0" 200 5999 "REFERER" "Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0 Mobile/14B100 Safari/602.1" IPADDRESS – – [03/Dec/2016:10:08:08 +0000] "GET / HTTP/2.0" 200 5999 "REFERER" "Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac […]

Nginx的uWSGI响应被截断

我试图在http://dont-tread-on-memes.controversial.io上写一个networking服务作为一个笑话。 这是一个烧瓶应用程序,提供相当大的图像。 Flask应用程序可以独立运行,就像一个独立的uWSGI服务器一样,但是当我尝试通过uwsgi_pass将uWSGI插入到NGINX中时,突然间所有其他的请求在浏览器中被截断为9.99KB。 阅读与proxy_pass类似的截断之后,我试过: 在我的configuration文件中设置uwsgi_buffering off 使用uwsgi_buffers 1024 1024k; uwsgi_buffer_size 1024k;将缓冲区大小1024k uwsgi_buffers 1024 1024k; uwsgi_buffer_size 1024k; uwsgi_buffers 1024 1024k; uwsgi_buffer_size 1024k; sendfile: off 检查缓冲区文件权限( /var/lib/uwsgi中的所有文件都由www-data用户和www-data组拥有,所以我认为我的权限很好。) 我留下了我目前的configuration,这仍然performance出这个问题: server { listen 80; server_name dont-tread-on-memes.controversial.io; location / { include uwsgi_params; uwsgi_pass unix:/var/www/dont-tread-on-memes/dont_tread_on_memes.sock; uwsgi_buffers 1024 1024k; uwsgi_buffer_size 1024k; } } 最奇怪的部分是,这个问题只出现在第二个请求。 它必须与NGINXcaching有关,因为我没有使用多个NGINX实例或任何东西。 然而它必须与我的NGINXconfiguration有关,因为uWSGI自己运行不会出现问题。 有什么想法可能导致这个问题,以及如何解决它?

使用nginx,如何限制每个预读主机名或上行访问代理TCP资源?

nginx 文档和指南显示,您可以在stream块中执行基于IP的白名单/黑名单。 但是,我不知道如何allow / deny基于IP的连接,只有某些使用SSL预读的主机名。 情况 我有一个nginx框代理专用networking上的许多服务。 其中一些服务应该暴露在networking之外,而有些则不应该。 这个nginx框代理内部和外部的连接。 # TCP proxying with SSL passthrough & vhosts stream { map $ssl_preread_server_name $name { public.example.com public; private.example.com private; default default_upstream; } upstream public { server 10.0.0.2:443; } upstream private { server 10.0.0.3:443; } upstream default_upstream { server 10.0.0.4:443; } server { listen 443; proxy_pass $name; ssl_preread […]

Nginx自己的云安全措施?

OwnCloud给我: X-XSS-Protection HTTP头未configuration为等于"1; mode=block" 。 这是潜在的安全或隐私风险,我们build议调整此设置。 X-Content-Type-Options HTTP头未configuration为等于nosniff 。 这是潜在的安全或隐私风险,我们build议调整此设置。 X-Frame-Options HTTP标头未configuration为等于SAMEORIGIN 。 这是潜在的安全或隐私风险,我们build议调整此设置。 我应该如何保护它?

最大bantime与fail2ban

我正在使用fail2ban/firewalld来限制对Nginx服务器的类似bot的访问。 通常,相应的监狱configuration如下所示: [nginx-botsearch] #banaction = iptables-multiport enabled = true filter = nginx-botsearch logpath = /var/log/nginx*/*access*.log maxretry = 3 bantime = 3600 这按预期工作(缺省值为firewallcmd-ipset ),即iptables -L命令在INPUT_direct链中显示一个条目: REJECT tcp — anywhere anywhere multiport dports http,https match-set fail2ban-nginx-botsearch src reject-with icmp-port-unreachable 与相应的fail2ban-nginx-botsearch ipset 。 但是,当bantime增加时,我注意到一个奇怪的行为。 一切正常预计bantime <= 4294967 。 当我设置bantime = 4294968并重新加载fail2ban服务时, iptables输出中的条目丢失(ipset未被创build),实际上,使用例如ab实用程序进行testing显示禁止未被强制执行。 有趣的是,使用banaction = iptables-multiport即使对于“大型”禁令也是如此。 什么可能是这种行为的原因? 我在CentOS 7上使用了fail2ban […]

在nginx上redirect57,000个URL的最好方法是什么?

我打算在像下面的例子那样使用映射文件在nginx中做很多redirect,但是我发现我必须redirect大约57,000个URL。 把它们放在像这样的configuration文件中是最好的方法,还是有更好的方法? map $request_uri $redirect_uri { /old-path-1 /new-path-1; /old-path-2 /new-path-2; /old-path-3 /new-path-3; } redirect主要是为search引擎。 在他们重新编制网站索引之后,我认为在旧的url上不会有大量的点击。 我主要关心的是创build一个configuration文件,其中有许多行的潜在问题。