Articles of nginx

使用nginx http代理使用子域的REST风格的API调用

我已经将godaddy子域名backend.example.com和app.example.com转发给Google Compute Engine的相同公开IP XXX.XXX.XXX.XXX。 我configuration了nginx webserver,并且我的springboot后端正在端口8090上运行。目前使用以下configuration – server { listen 80; gzip on; server_name backend.example.com; location / { root html/example; index index.html; } location /private { proxy_pass https://127.0.0.1:8090; } location ~* \.(gif|jpg|jpeg|png|js|css)$ { } } 我的networking应用程序工作正常。 但是REST风格的api调用只在url是http://XXX.XXX.XXX.XXX/api/view时才起作用 。 当使用http://backend.example.com/api/view作为url时,获取下面的html响应 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Backend</title> <META name="description" content="Backend"> </head> <frameset rows="100%,*" […]

nginx access_log关不起作用

我有一个像这样的nginx站点configuration。 我想要所有的位置login到access_log,除了在configuration中提到的。 但是这个configuration会将所有/ event / lp urllogging到访问日志中。 我错过了什么吗? server { listen 443 ssl http2; access_log /var/log/nginx/sub.example.com.log all; server_name sub.example.com; ssl on; ssl_certificate /etc/nginx/ssl/example.crt; ssl_certificate_key /etc/nginx/ssl/example.key; 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; client_max_body_size 20m; client_body_buffer_size 128k; proxy_connect_timeout 900; proxy_send_timeout 900; proxy_read_timeout 900; proxy_buffer_size 32k; proxy_buffers 4 32k; location ~ ^/event/ws […]

Nginx的“auth_basic”string编码

nginxconfiguration文件中正确的编码/字符集是什么,以显示HTTPauthentication信息中的突出字符? 例如,这个conf文件: server { … location / { auth_basic "Zone sécurisée"; auth_basic_user_file .htpasswd; } } 在Firefox的提示窗口显示: “Zonesécurisée” 没有真正的解决scheme或在网上find解释。 我试着用confreplaceconf文件中的é ,用&amp; ,通过&#233 ,通过=C3=A9或添加charset utf-8指令或=?UTF-8? 在string的开头,但没有任何工作! 官方的nginx文档,谈论一个“string”,没有更多解释强调字符的编码。 注意:我对Apache的.htaccess文件没有问题

Nginx加健康检查不起作用

Nginx / 1.11.10(nginx-plus-r12-p3)。 这是我们的configuration: upstream cara { zone cara 64k; least_conn; keepalive 50; server xx.xx.xx.xx; server xx.xxx.xx.xx; … } location / { … proxy_http_version 1.1; proxy_next_upstream error http_502 timeout non_idempotent; proxy_connect_timeout 3s; proxy_buffers 10000 8k; proxy_read_timeout 630s; client_body_buffer_size 100M; keepalive_requests 2000; keepalive_timeout 2m; health_check mandatory uri=/health/check; proxy_pass http://cara; } / health / check返回状态200,但是nginx甚至不访问此uri并将所有服务器标记为失败。 我在configuration中缺less什么?

NextCloud作为Oauth提供者

我注意到在一些当前版本的NextCloud中,有一个用于添加Oauth 2.0客户端的pipe理菜单选项。 这样做会给您一个客户端ID和一个客户端密码,就像您所期望的一样,并且可以接收redirect的URL。 现在的问题是,我如何使用这个。 我只find一个在网上使用它的提及,就是这样 。 我目前正在使用Github的Bitly的Oauth2代理,可以在这里find。 我的networking服务器是Nginx,我正在运行NextCloud 12.我有另一个内部应用程序,我也托pipe,这是运行在一个空的GitLab安装和GitLab安装被用作一个Oauth 2反向代理通过之前进行身份validation到我们的内部软件。 任何帮助或指针都会很棒,这似乎是NextCloud的一个非常强大的function,它似乎没有任何支持/文档​​。 为了更具体一些,我会尽力更好地解释我目前的设置,以及我想要的样子。 当前: 如果您愿意,我有3个“子网站” GitLab: www.site.com/subsiteA/ NextCloud: www.site.com/subsiteB/ 内部www.site.com/subsiteC/ : www.site.com/subsiteC/ 用户访问www.site.com/subsiteC并退回到www.site.com/subsiteA/的GitLablogin页面。 login成功后,他们将跳回到www.site.com/subsiteC/ 。 同样,如果您访问www.site.com/subsiteB/ ,则通过www.site.com/subsiteA/进行代理,但用户仍需通过NextCloudlogin。 (去subsiteA直接到GtiLab) 理想的设置: NextCloud: www.site.com/subsiteA/ 内部www.site.com/subsiteB/ : www.site.com/subsiteB/ 如果你去www.site.com/subsiteB/你通过subsiteA反弹,但就是这样。 在此设置中,在login到NextCloud之前,不需要login到GitLab。

nginxredirect/只重写主机名

当使用服务器的唯一短主机名时,我在将https请求redirect到Nginx服务器时遇到了一些麻烦。 我尝试了所有例子的组合,但似乎没有触发redirect/重写。 例如,服务器被称为web01,并且我希望所有请求都转到https://web01.domain.com 。 我有http – > https重写完美的FQDN。 但是,如果我尝试去https:// web01 ,它将继续尝试加载页面,显然证书不匹配错误。 我希望它重写到FQDN的请求。 我怎样才能configuration重写/redirect? 我现在拥有的: server { listen *:80; rewrite ^ https://web01.domain.com$request_uri permanent; } server { listen 443 default ssl; server_name web01.domain.com; }

无法重新启动php7.0-fpm。 儿童进程挂

要清除我的PHP应用程序的opcache,我希望能够重新启动php7.0-fpm.service 。 我使用Ubuntu 17.04(Zesty Zapus),nginx / 1.10.3和php-fpm7.0。 在服务器上,我正在通过gluster挂载一个文件系统。 当我的应用程序运行一段时间,我尝试重新启动php-fpm与systemctl restart php7.0-fpm.service它需要很长时间来终止命令。 之后,PHP的FPM不会再次启动。 systemctl restart php7.0-fpm.service Job for php7.0-fpm.service failed because the control process exited with error code. See "systemctl status php7.0-fpm.service" and "journalctl -xe" for details. 重启之前的进程列表: root 819 0.0 1.4 366356 58764 ? Ss Jul10 0:02 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf) www-data 23129 0.0 0.8 […]

试图代理HTTPS,但得到:收到意外的TLS数据包

在一个端口上有一个HTTPS服务器(5006)。 我想在35001上提供它,并在同样的35001上也提供其他服务(通过添加/app , /auth , /admin等位置)。 服务器是auth-server.org.local 。 试着添加一个端口: server { listen 35001; location / { proxy_pass https://auth-server.org.local:5006; } } 输出: $ curl -k -X GET https://auth-server.org.local:5006 <h1>My auth server</h1> $ curl -k -X GET https://auth-server.org.local:35001 curl: (35) gnutls_handshake() failed: An unexpected TLS packet was received. 为什么35001不起作用? 我错过了什么? 我使用过这个指南: https : //www.nginx.com/resources/admin-guide/nginx-https-upstreams/

nginx从request_uri中提取并将其添加到redirct目标

我目前正在使用nginx将现有网站的新版本移植到新的服务器上,并且已经被告知URL需要指向新的PHP文件来处理如何从新的数据库中挑选date。 一个传入url的例子是: https://testsite.com/test-account-here-ABC-123456.html 这是由nginx抓到并redirect到 https://testsite.com/profiles.php 在那里文件将做它的位,并提取url,以获得其细节,并进行search。 我已经build立了一个redirect的前提下,$ request_uri在URL中find** – ABC- *,如下所示: if ($request_uri ~ ^/(.*)-ABC-) { return 302 $scheme://testsite.com/profile.php; } 成功去那个PHP文件,但我需要能够从URL(123456)中提取数字,所以我可以通过查询string在PHP文件中访问它们,我试图用户 return 302 $scheme://testsite.com/profile.php?url=$request_uri; 但是这会返回导致无限redirect循环和浏览器错误的完整url。 有无论如何,你可以提取一个$ request_uri的部分,然后重新使用redirect? 东西沿线 return 302 $scheme://testsite.com/profile.php?url=$variable1;

nginx,lua和响应时间

我有一个nginx负载均衡器,它只是代理请求到less数上游服务器。 现在,我想要做的是: 对于十个请求中的一个,我想测量nginx的响应时间(以毫秒为单位),并将该值转发到InfluxDB度量标准数据库。 我不知道如何才能使这项工作。 我最初的想法是利用“access_by_lua_block”function,但如果我理解正确,这是在请求发送到上游服务器之前执行的。 从上游服务器接收到响应后,是否有办法执行lua-code? 只是要清楚:我想要nginx负载均衡器本身的响应时间,而不是上游应用程序服务器的响应时间。 我的最终目标是比较负载均衡器的响应时间和上游服务器的响应时间,以确定负载均衡器configuration中的潜在瓶颈。