Articles of nginx

NGINX双反向代理

我正在遇到我的反向代理的一些奇怪的问题。 我的设置看起来像这样: setup 现在,我的内部networking中的主机可以到达服务器srv1.my.domain.org上的localhost:3000上运行的应用程序,所以我知道configuration工作。 但只要我尝试从networking外部访问应用程序(通过gateway.my.domain.org ),我只能看到NGINXtesting页面。 我不明白为什么,因为这个configuration我已经做了多个其他的应用程序,他们正在工作。 注: server_name与物理服务器的主机名相同。 这里是configuration: gateway.my.domain.org path: /etc/nginx/conf.d/app.my.domain.org.conf upstream srv { server srv1.my.domain.org; } server { listen 443; server_name gateway.my.domain.org; ssl on; ssl_certificate /…/fullchain.pem; ssl_certificate_key /…/privkey.pem; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; ssl_prefer_server_ciphers on; access_log /var/log/nginx/gateway.access.log; error_log /var/log/nginx/gateway.error.log; client_max_body_size 150M; location / { proxy_set_header Host $host; proxy_set_header […]

我如何提供域掩码

我运行一个网站foo.com 。 我想为运行bar.com客户提供域掩码。 具体而言,他们希望xyz.bar.com从foo.com/abc加载内容,以便访问者永远不会离开xyz.bar.com域。 这是许多Web服务的一个标准function,它通常包括bar.com人员为xyz.bar.com创build一个DNS条目,指向foo.com提供给他们的IP地址(例如123.0.0.2 )。 但是我如何在foo.com结束呢? 我必须为每个bar.com子域设置一个单独的IP地址( 123.0.0.xxx )吗? 在我的最后设置nginx的正确方法是什么,以便给定的xyz被映射到适当的abc ? 我是否需要获取xyz.bar.com证书并将其安装在我的terminal上? 另外作为一般说明,一个xyz总是对应于一个abc ,但是这些对有很多实例。 任何有关如何自动化过程的build议,我们将不胜感激。 我已经看过,不想要的东西: iframes ,这是在客户端的工作,并在大多数技术的范围。 URL重写等。 这是最好的解决scheme,我的应用程序代码因客户端和/abc特殊shell丢失而变得复杂。

将$ request_body_file复制到另一个文件中

我需要将请求主体的二进制内容存储在服务器文件系统中的文件中。 没有CGI,PHP或任何其他可用的可执行文件,因此只是在寻找使用nginx的东西。 我发现,当POSTing nginx将请求体的内容保存到由$ request_body_file指向的特定文件中时。 是否有任何nginx指令将此文件复制到服务器内的某个位置(服务器有写入权限)? 欢迎任何其他build议。

使用DNS / nginx将子域指向单独的IP地址

我试图在不同的服务器上指向一个不同的IP地址,但由于某种原因,它只能在一段时间内每隔一段时间工作(比如20次中的1次)。 浏览到http // galera.domain.com会抛出一个“花费很长时间来响应”错误,并将URL更改为https // galera.domain.com。 直接浏览IP地址一直正常。 这是我目前的设置: 服务器1(nginx): IP_ADDRESS_1。 已启用HSTS [严格的传输安全(max-age = 63072000; includeSubdomains)] domain.com / www.domain.com的DNS指向IP_ADDRESS_1 server { listen 80 default_server; listen [::]:80 default_server; server_name domain.com www.domain.com; return 301 https://$server_name$request_uri; } server { # SSL configuration listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; include snippets/ssl-domain.com.conf; include snippets/ssl-params.conf; root /var/www/html; index […]

Nginx反向代理到上游得到502坏网关?

我当前的应用程序部署正在接收HTTP端口上的stream量,Nginx将其redirect到HTTPS。 这工作正常。 现在我们打算让另一个Nginx服务器像这个现有的Nginx服务器(也称为Upstreams)一样负载平衡器。 下面是我正在尝试的configuration upstream web_rack { server xxxx; } server { location / { proxy_pass https://web_rack; } } 但以下日志得到502 Bad Gateway错误: 2017/03/14 06:23:49 [error] 2402#2402: SSL SSL握手到上游客户端:189.166.35.243,服务器SSL_do_handshake()失败(SSL:错误:140770FC:SSL例程:SSL23_GET_SERVER_HELLO:未知协议) :,请求:“GET / HTTP / 1.0”,上游:“ https:// xxxx:80 / ” 提前致谢。

在HTTPS的sslconfiguration之后,Nginx无法重新启动

我想通过https服务我的网站,因此我完全按照给定的方式跟随了本教程 。 在第5步sudo nginx -t给出了积极的结果,因为configuration是好的。 当我跑sudo systemctl restart nginx它给出了以下错误 Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. 当我检查/var/log/nginx/error.log错误日志,如果显示此错误 2017/03/14 07:35:20 [emerg] 12111#12111:bind()到0.0.0.0:443失败(98:地址已经在使用) 2017/03/14 07:35:20 [emerg] 12111#12111:bind()到0.0.0.0:443失败(98:地址已经在使用) 2017/03/14 07:35:20 [emerg] 12111#12111:bind()到0.0.0.0:443失败(98:地址已经在使用) 2017/03/14 07:35:20 [emerg] 12111#12111:bind()到0.0.0.0:443失败(98:地址已经在使用) 2017/03/14 07:35:20 [emerg] 12111#12111:bind()到0.0.0.0:443失败(98:地址已经在使用) 2017/03/14 07:35:20 [emerg] 12111#12111:仍然无法绑定() […]

Apache-2.4作为NGINX的反向代理 – Log Real IP

我在windows上configuration了apache-2.4作为我的内部nginx服务器的反向代理(我知道!但是不要问我为什么!!)。 几乎一切都很好,除了: 我相信我已经configurationnginx使用这个头来logging真实的IP: X-Real-IP 。 参考 。 现在在我的反向代理中,我该如何设置这个头部到客户端的IP地址,以便它可以被logging。 请注意,SSL是apache-2.4上的必备工具。 目前我的http-vhosts.conf有这个: <VirtualHost _default_:443> RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Forwarded-Ssl on RequestHeader set X-URL-SCHEME https ServerName www.external.gateway:443 ServerAlias external.gateway:443 ErrorLog "C:/Apache24/logs/gateway-error.log" CustomLog "C:/Apache24/logs/gateway-access.log" common # ServerAdmin [email protected] SSLEngine On SSLCertificateFile C:/Apache24/ssl/external.gateway.crt SSLCertificateKeyFile C:/Apache24/ssl/external.gateway.key <Location /> SSLRequireSSL </Location> ProxyPreserveHost On ProxyPass / http://internal.nginx:80/ ProxyPassReverse / http://internal.nginx:80/ </VirtualHost> […]

nginx将子目录path作为参数

我想提供子目录path作为参数。 例如: http://www.example.com/whatever 其实去: http://www.example.com/?arg=whatever 但仍显示为原始请求url。 文件的path应该是一样的: http://www.example.com/whatever/image.png 其实去: http://www.example.com/?arg=whatever/image.png 我对nginx不是很熟悉,而且我也没有find或者能够创build我想要的东西。 到目前为止,我来到的最远的地方是: location ~ /(?<anydirectsubdirectory>[^/]+) { try_files $uri $uri/ /index.php?project=$anydirectsubdirectory; } 但是这只给了我第一个目录,我不知道或者能够find任何能够解释什么是什么的东西,所以如果你有一个解释这个东西的链接,那会对我有所帮助。

自动重新加载Nginx的certboot更新成功?

每隔三个月,我的Let's Encrypt证书过期,我的客户将收到一个无效的https证书。 所以我最近放了下面的cron任务: @weekly certbot renew –quiet && service nginx reload 根据我的理解,当certbot renew成功时更新证书,它返回一个成功的状态(exit(0)),所以跟随&& ,所以nginx被重新加载。 是的,但不起作用。 我最近有我的服务器再次显示过期的证书,所以我当然误解了一些东西,和/或我的cron任务不好。 你能告诉我path吗? 🙂

Nginxconfiguration不断抛出一个redirect循环,同时试图将wwwredirect到非www和https

我正尝试将所有www请求redirect到我的网域,而不是wwwurl,并且所有内容都是https 。 这是我的nginxconfiguration: server { listen 80; server_name example.com www.example.com; location '/.well-known' { default_type "text/plain"; root /home/letsencrypt; allow all; } return 301 https://example.com$request_uri; } server { listen 443 ssl http2; server_name www.example.com; include snippets/ssl-example.com.conf; include snippets/ssl-params.conf; location '/.well-known' { default_type "text/plain"; root /home/letsencrypt; allow all; } return 301 https://example.com$request_uri; } server { listen 443 ssl […]