Articles of nginx

Nginx的file upload,文件去哪儿了?

我正在尝试configurationnginx来支持file upload。 我正在使用这里描述的方法。 我的nginx.conf如下所示: location /upload { limit_except POST { deny all; } client_body_temp_path /tmp; client_body_in_file_only on; client_body_buffer_size 128K; client_max_body_size 20G; return 201 $request_body_file; } 这里的想法是通过打开client_body_in_file_only ,每个请求被直接保存到磁盘。 而且它保存的文件名也被返回给客户端。 我可以用cURL上传文件,并看到它们正在全部转移: $ curl -i -F "[email protected]" http://server/upload > out.txt % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed […]

Nginx邮件代理隐藏客户端的IP

我用auth_http成功地设置了nginx的imap / pop3邮件代理服务器,这个代理服务器已经运行好几个月了。 最近,在imaplogin中提出了在mail.log中显示客户IP的请求。 由于Nginx与Dovecot通信,日志中的IP地址属于Nginx服务器(在本例中为127.0.0.1,因为它们在同一台服务器上)。 到目前为止,我找不到解决scheme或解决方法。 显然,即使在nginx邮件区块中也不能logging。 最接近的命中是Dovecot( https://wiki2.dovecot.org/HAProxy )中的HAProxy支持,但我不确定是否与Nginx类似。 任何帮助表示赞赏。 谢谢

如何将以.PHP结尾的特定urlredirect到Nginx中的另一个url?

如果URL以.HTML结尾,我没有问题控制它,并在Joomla中redirect。 但是如果以.PHP结尾,我会得到404页面。 我认为它可以解决以下两种方法之一:1.给Joomla控制以PHP结尾的URL,以便我可以从Joomla或2中redirectURL。尝试在NGINXconfiguration中执行: location / { try_files $uri $uri/ /index.php?$args; } location /oldsignup.php { rewrite ^/.* http://example.com/signup.html permanent; } location /oldsignup2.php { rewrite ^/.* http://example.com/signup.html permanent; } 我试过以上,但失败了。

覆盖特定位置的CSP标头

我有一个nginxconfiguration,包括一个CSP头,为所有请求服务。 现在我需要重写它在一个特定的位置(这也恰好被重写)。 我在想这样的事情: server { listen 80; listen [::]:80; server_name example.com; root /var/www; index index.php; try_files $uri @rewrites; add_header Content-Security-Policy "default-src 'self' ; script-src 'self' ; style-src 'self' 'unsafe-inline' ; img-src * 'self' data: ; font-src 'self' ; media-src * 'self' ; form-action 'self'"; location @rewrites { rewrite ^/special/([0-9]*) /special.php?id=$1 last; rewrite ^/foo/([az]+) /foo.php?method=$1 last; […]

nginx反向代理设置来处理上游服务器的正常部署

我目前的设置是nginx作为一个负载平衡器,在一堆上游服务器前面。 我希望能够在不改变用户体验的情况下进行部署。 这意味着没有502s,也没有增加页面时间。 我的理解是,当发出nginx -s reload时,nginx将优雅地产生新的线程来处理新configuration的新连接,但仍将完成处理nginx -s reload时nginx -s reload请求。 而且,我已经在某处看到上游区域的上游处于下行状态,重新装载将从轮stream上游处取得,但仍将完成与上游的任何空中连接。 这是正确的吗? 目前的计划是在nginx主机上有一个小的进程,这将基本上改变nginx的configuration,并通过内部的REST API要求这些优雅的重新加载。 然后,我的部署工具将连接该进程,并在正常closures和每个上游的启动/预热完成之后,依次从nginxconfiguration中添加/删除我的上游。 这有道理吗? 其他人怎么做呢? 有没有可用的工具呢? 我没有很多运气search这个信息…

删除nginx日志前缀

我configurationnginxlogin这种格式 log_format lalala '$remote_addr – $remote_user '; access_log syslog:server=unix:/dev/log lalala; 但是,每一行都以 testserver nginx: 尽pipe它没有从我的日志格式。 这意味着,加上journald,我有我的主机名和“nginx”每个日志行两次。 有没有办法去除那个东西? 我没有find办法。

Docker 1.13“Swarm Mode”群集的nginx反向代理

我有一个现有的docker群集群运行在两个节点,我想添加nginx反向代理。 我在问这个问题,因为我面临着一些我不知道如何解决的问题。 我的第一个问题是关于在Swarm中运行nginx,并能够使用它们的专有名称访问我的应用程序容器。 首先,这里是docker network ls的输出 6897486e798b bridge bridge local 3c5b72414821 docker_gwbridge bridge local 6f762b23ff12 host host local uwy3qfuu4oos ingress overlay swarm 0e867cd5a3bf none null local 我是否需要创build另一个覆盖networking,并将Nginx设置为覆盖networking。 我以下面的方式创buildnginx服务: docker service create rproxy -p 80:80 –mount type=volume,source=rproxy,target=/etc/nginx –mode=global nginx:alpine 使用这个命令,nginx正在我所有的节点中创build,我可以使用浏览器访问默认的nginx“hello world”屏幕。 因为我为nginxconfiguration挂载了卷,所以我可以从/var/lib/docker/volumes/rproxy/_data访问nginxconfiguration。 于是,我进入了/etc/nginx/conf.d ,删除了default并创build了一个简单的vhost: server { listen 80; location / { proxy_pass http://myapp:80; } } 当我重新启动nginx时,由于Host […]

Nginx不会将自定义域请求转发到正确的端口

我有一个网站,允许用户为他们的网站创build投资组合,他们只需在他们的域名上更改他们的Alogging,并将我的服务器IP地址logging到他们的logging中,并将映射到他们的网站(user1.example.com)。 我的问题是,我购买了一个域来testing(example.com),它将它们路由到我的实际网站的主页,您可以使用此服务。 用户访问他们的网站的唯一方法是通过: http://example.com:3000 : http://example.com:3000 : http://example.com:3000是我的Node.js应用程序运行的端口。 我的Nginxconfiguration如下,有人可以扔我骨头? server { listen 80; listen 443 ssl; listen [::]:443 ssl; ssl_certificate /etc/nginx/ssl/example.com/cert_chain.crt; ssl_certificate_key /etc/nginx/ssl/example.com/example.com.key; server_name example.com *.example.com ""; access_log /var/log/nginx/nginx.vhost.access.log; error_log /var/log/nginx/nginx.vhost.error.log; root /opt/33i/; # Perfect forward secrecy ssl_prefer_server_ciphers on; ssl_dhparam /etc/nginx/ssl/example.com/dhparams.pem; ssl_ciphers ; # HSTS add_header Strict-Transport-Security "max-age=31536000; includeSubdomains"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; location / […]

Nginx将proxy_pass服务器redirect到http://server/index.html

我有以下configuration: server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; location / { index index.html; } server_name command_asdf location /asdf/ { proxy_pass http://127.0.0.1:3001/; } 当我去http://server/asdf/index.html一切工作正常。 但是,如果我转到http:// server / asdf /或http:// server / asdf,那么它们都会将我redirect到http://server/index.html而不是http://server/asdf/index.html 我花了好几个小时试图弄清楚如何让它redirect到子目录上的索引页面,但可悲的是没有成功。 我有一些服务器,我需要使用proxy_pass上,但是上面是最简单的configuration,我可以显示。 谢谢!

处理无通配符SSL证书的无效子域

我希望能够处理无效子域名(如https://wwwe.mydomain.com请求,以显示有意义的错误消息(示例https://sdfsdf.github.com )。 我的nginxconfiguration目前只能用于非http地址。 对于https://位置,浏览器会引发错误,因为我的SSL证书上没有子域名。 我有来自letsencrypt的证书,不允许通配符,我不能从其他提供者那里获得证书。 有没有办法解决?