Articles of nginx

Nginx – 扩展variables内的variables(string)

一个“有趣”的问题,而不是在生产中无法克服的东西,但是我一直在试图find一种方法来扩展其他variables的variables。 例如:在下面的代码块中,我在auth_request的后面设置了一个上游variables。 我的auth_request uwsgi应用程序将尝试多个身份validation方法,根据API的可用性,如果没有当前会话,将redirect到多个login应用程序之一。 特定的login应用程序URL在auth尝试后作为forward_to头被返回,然后nginx将302那个URL。 我想在这个头文件中提供nginxvariables,比如$scheme://$host$uri并且让它们用redirect来扩展,但是在这个例子中,redirect是指向文本stringhttps://example.com/login?referrer=$scheme://$host$uri 而不是扩展到https://example.com/login?referrer=https://example.com/page 。 那么,你有什么想法或想法如何实现呢? # Authenticate requests. auth_request /auth/; auth_request_set $forward_to $upstream_http_forward_to; # forward_to set to https://example.com/login?referrer=$scheme://$host$uri string error_page 401 =302 $forward_to; # Hope variables expand # Authentication handler. location /auth/ { uwsgi_pass unix:/tmp/auth.sock; include uwsgi_params; uwsgi_param SCRIPT_NAME /auth; } 干杯!

Nginxredirect循环与多个proxy_pass和主机头

我的使用案例 我需要能够设置两个proxy_passes:一个用于发送主页,/,到webflow.test.co,同时保持URL(test.co),另一个用于路由所有其他请求 – /(.+) – 我的Nodejs服务器(例如,test.co/api,test.co/media,test.co/login)。 最后,我想指定具体的terminal去每个地方,但现在看来没有解决这个问题。 问题 将这两个位置块一起添加到主页的无限redirect循环中。 我已经尝试了几乎所有我能想到的,并find解决这个问题的方法。 唯一的办法是删除主机头(proxy_set_header主机),这会留下显示代理URL(webflow.test.co)的不良影响。 我尝试添加斜杠到我的代理URL,添加X-Forwarded-Proto头(webflow.test.co是https),删除顶部的两个服务器块(只是为了testing),并将server_name设置为简单test.co和删除正则expression式。 至less这些是主要的事情。 值得一提的是,这是在ElasticBeanstalk节点上运行的,它们使用默认的nginx设置。 以下是我的nginx.conf。 请随时索取任何其他信息。 这是我的代码: upstream nodejs { server 127.0.0.1:8081; keepalive 256; } # Redirect all non-HTTPS to non-WWW HTTPS server { listen 8080; server_name "~^(?:www\.)?(.*)$"; return 301 https://$host$request_uri; } # Redirect WWW HTTP to non-WWW HTTP server { listen 4430; server_name "~^www\.(.*)$"; […]

DEBIAN – Nginx和Apache反向代理丢失HTTPS状态?

我在configurationDebian 8机器上的nginx和apache时遇到了一个问题。 我使用nginx的反向代理,它被设置为在HTTPS上运行(它的工作原理就像一个魅力)。 但是,当请求被发送到Apache,$ _SERVER ['HTTPS']是空的,虽然它应该是“开”(无论如何,这就是我想实现)? 这是我的Apacheconfiguration: <VirtualHost 127.0.0.1:8080> ServerName shop.mywebsite.com ServerAdmin webmaster@localhost DocumentRoot /var/www_shop ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined LogLevel debug <Directory "/"> Require all granted </Directory> </VirtualHost> 下面是我的nginx congif,部分代理密码: location ~ \.php { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Original-Request $request_uri; add_header Front-End-Https on; proxy_pass http://127.0.0.1:8080; […]

如何修复“SCRIPT_NAME”而使用php-cgi运行php脚本?

我正在尝试使用腻子在WordPress中运行下面的PHP文件。 php-cgi -f info.php 但是这个命令会抛出这个错误的未定义索引:SCRIPT_NAME。 服务器设置: #fastcgi_param HTTPS $fastcgi_https; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; 请帮我解决这个问题。

NGinx窗口Auth_base失败

我在windows server 2012上设置了简单的nginx服务器(1.13.5)。我将它configuration为使用基本身份validation,如下所示: server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; auth_basic "Restricted"; auth_basic_user_file c:/Software/nginx-1.13.5/conf/password; } 但是,当我尝试在给定用户下login时,我在日志中获得以下logging: *5 user "admin" was not found in "c:/Software/nginx-1.13.5/conf/password", client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost" 这是我的密码文件: admin:$2y$05$ALMoM9YZU53aSsJh6uL.OuVLbb5GlkyjQMFi2FNcQDkaxftf5e9PW 现在这显然是NGinx中的一个bug。 使用MD5对密码进行散列,并且使用Apache htpasswd.exe创build该密码,并且从当前版本(并根据文档)进行散列。 只是可以肯定的是,我也尝试使用openssl的结果相同。 有没有人知道一个解决方法,或者甚至可以修复这个bug?

无法获取/parsing/function/

我对维护Parse很陌生,但我已经疯了;) 我们有一个在debian机器上的parsing服务器设置。 它运行nginx并使用pm2来部署Parse。 Parse-Dashboard运行良好,即使我们的parsing服务器也在popup它的mongodb。 但是,服务器似乎并没有为我们工作。 我们可以访问domain.com/parse/serverinfo ,例如domain.com/parse/users ,它会向我们显示正确的用户列表。 然而,从我们的云代码调用我们的任何function是不可能的,这是行不通的。 我一直在searchgoogling和googling这个问题,而我似乎能find的最多的人是他们的index.js中的mount参数configuration不正确。 但是,我们并不是这样。 这是我们的index.js: // Example express application adding the parse-server module to expose Parse // compatible API routes. var express = require('express'); var ParseServer = require('parse-server').ParseServer; var path = require('path'); var S3Adapter = require('parse-server').S3Adapter; var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI; if (!databaseUri) { console.log('DATABASE_URI not specified, […]

Django,Nginx和Gunicorn上的SSL

我使用Nginx和gunicorn来为我的Django项目服务。 我目前正在为SSL(https)工作,但不太了解设置文件和Nginx的正确设置。 有人可以看看我的设置,并告诉我,如果有任何公然看起来错误,或可怕的执行? 我的Nginx文件,请注意,有些行被注释掉。 当我取消注释时,该网站停止工作。 编辑:当我在同一时间/ server { server_name example.com; listen 443 ssl; ssl on; ssl_certificate /etc/ssl/mycrt.crt; ssl_certificate_key /etc/ssl/mykey.key; location = /favicon.ico {access_log off; log_not_found off;} location /static/ { gzip on; gzip_types text/css; alias /home/project/static/; } location / { include proxy_params; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; # proxy_set_header Host $http_host; # proxy_redirect off; […]

.bit域名在Nginx CentOS上

目前我试图添加domain.bit作为我的server_name在Nginx中,我已经成功完成,但是,当转发域到服务器的IP甚至ping域,它无法启动服务器的IP。 这是我目前的conf: # # The default server # server { listen 80; server_name domain.bit; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server […]

jwilder / nginx-proxy设置多个php fpm容器

我试图用mailcow-dockerized( https:// github )运行官方的nextcloud docker-compose.yml( https://github.com/nextcloud/docker/blob/master/.examples/docker-compose.yml ) .com / mailcow / mailcow-dockerized )项目在一个vps。 它实际上工作,我可以访问浏览器中的两个应用程序(即使电子邮件发送和接收工程):),只有一个缺点,只要两个应用程序尝试访问FMP,VPS崩溃。 所以我想这可能要做,他们都想访问主机的端口9000。 所以接下来我要做的就是改变每个主机的configuration来添加fastcgi pass: .examples/proxy/VIRTUAL_HOST_location fastcgi_pass nextcloud_fpm:9000; 但是我得到一个没有nginx或fastcgi错误的空白页面( docker logs proxy -f –since 2 )。 和docker logs nextcloud_fpm -f –since 2输出以下内容: 172.19.0.7 – 08 / Sep / 2017:13:07:32 +0000“ – ”200 172.19.0.7 – 08 / Sep / 2017:13:07:40 +0000“ – ”200 version: […]

nginx – 'valid_referers'或者替代'no-referrer-when-downgrade'而不使用'none'

tl; dr:与nginx – 使用“valid_referers”是否有一种方法来允许一个域时,没有引用(r)呃信息被返回 – 但不诉诸“无”? 例如,当说,防止盗链? 或者使用“valid_referers”的一个很好的select? 我已经花了几天的时间来search,开始和结束。 例如。 假设我想允许从example.com盗链。 以下内容对于“降级时没有引荐者”这个词不会有用。 location ~ .(jpg|jpeg|png|gif)$ { valid_referers server_names *.example.com www.example.com; if ($invalid_referer) { return 403; } } 因此,我们可以添加“无”(和“阻止”好的措施) – 但据我了解,任何“无”或“封锁”都将允许盗链。 喜欢这个。 location ~ .(jpg|jpeg|png|gif)$ { valid_referers none blocked server_names *.example.com www.example.com; if ($invalid_referer) { return 403; } }