我有一个托管在 Heroku 上的 Web 应用程序,它使用 Django,域为(比如说)example.com。我想让所有传入http://example.com请求重定向到https://example.com.
我在 Django 中设置了SecurityMiddleware并设置SECURE_SSL_REDIRECT为“将所有非 HTTPS 请求重定向到 HTTPS”。这似乎有效。True
Heroku 充当我的 Django 应用程序的代理。因此,当 Heroku 负载均衡器收到 HTTPS 请求时,它(可能)使用非 HTTPS 连接路由到我的 Web 应用程序。这吓坏了我的应用程序,它再次将其重定向到 HTTPS,引发重定向循环。
解决这个问题的方法似乎是在 Django 中设置SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')为一个设置。这告诉我的应用程序:如果代理发送标头“HTTP_X_FORWARDED_PROTO”,并且其值为“https”,则信任该连接。我尝试过这个,它有效。
然而,Django 文档警告我,我应该确保我的代理删除传入的“X_FORWARDED_PROTO”标头,这是有道理的:如果恶意代理通过具有http值的连接发送此标头https,我的网络应用程序将被愚弄。
如何检查 Heroku 是否X_FORWARDED_PROTO从传入请求中删除标头?
我的 Nginx 配置类似于:
server {
listen 80;
listen 443;
server_name api.mysite.dev;
location / {
proxy_set_header Host "api.mysite.dev";
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $scheme://127.0.0.1:8001;
}
}
server {
listen 80;
listen 443;
server_name mysite.dev www.mysite.dev;
# Forward all /api/ requests ti api.mysite.dev
# sadly need to keep this around for backwards compatibility
location /api/ {
proxy_set_header Host "api.mysite.dev";
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $scheme://127.0.0.1:8001/;
}
# The proxy_pass here ends up putting the port (8002) in the response URL.
location / {
proxy_set_header …Run Code Online (Sandbox Code Playgroud) 是否可以只允许用户输入 xxxxxx.com(虚构),因此他们应该进行 DNS 查找并连接。并阻止使用我的公共 IP 进行连接的用户?
\n\n配置:
\n\nserver {\nlisten 80;\nreturn 301 https://$host$request_uri;\n}\n\nserver {\n\nlisten 443;\nserver_name xxxxxxx.com;\n\nssl_certificate /etc/nginx/ssl/server.crt;\nssl_certificate_key /etc/nginx/ssl/server.key;\n\nssl on;\nssl_session_cache builtin:1000 shared:SSL:10m;\nssl_protocols TLSv1 TLSv1.1 TLSv1.2;\nssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;\nssl_prefer_server_ciphers on;\n\naccess_log /var/log/nginx/jenkins.access.log;\n\nlocation / {\n\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto $scheme;\n\n # Fix the \xe2\x80\x9cIt appears that your reverse proxy set up is broken" error.\n proxy_pass http://10.0.11.32:80;\n proxy_read_tenter code hereimeout 360;\n\n proxy_redirect http://10.0.11.32:80 https://xxxxxxx.com;\n}\n}\nRun Code Online (Sandbox Code Playgroud)\n 在var/log/nginx/https-error_log和中var/log/nginx/http-error_log,我看到数千万个错误(过去几个月的汇总):
client xx.xx.xxx.xxx closed keepalive connection
Run Code Online (Sandbox Code Playgroud)
通常(但并非总是)它们成对存在,甚至具有相同的 IP 地址和时间戳,例如:
2016/07/12 19:24:59 [info] 44815#0: *82924 client 82.145.210.66 closed keepalive connection
2016/07/12 19:24:59 [info] 44821#0: *83275 client 82.145.210.66 closed keepalive connection
Run Code Online (Sandbox Code Playgroud)
即,似乎同一个人在同一时间点关闭了两次连接?我感觉这里有什么不妙的事情发生。我在gunicorn(它是一个Django 应用程序)前面使用nginx 作为反向代理。任何有专业知识的人都可以帮助我解决这个问题,或者推测它可能是什么?或者,这是我不应该担心的事情吗?
我有 apache 作为反向代理。apache的背后是.NET core应用程序。两者都使用 HTTPS。问题是,当我通过代理访问此 .NET 应用程序时,.NET 报告该请求是使用 http 在没有 SSL 的情况下发出的。
Apache 代理配置:
SSLProxyEngine on
<Location "/">
ProxyPass "https://domain:8444/"
ProxyPassReverse "https://domain:8444/"
</Location>
Run Code Online (Sandbox Code Playgroud)
Apache 可以通过https://domain/访问。
当我通过https://domain:8444/地址访问应用程序时,然后httpContext.Request.IsHttps==true和httpContext.Request.Scheme=="https",但是当我通过https://domain/访问应用程序时,然后httpContext.Request.IsHttps==false和httpContext.Request.Scheme=="http"。
当我尝试使用 PHP 进行相同的配置时,一切正常。有什么我可以做的吗?
我制作了一个 asp.net core 应用程序,并尝试使用反向代理将其托管在 Apache 中。该应用程序使用 cookie 身份验证:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "CookieAuthentication",
LoginPath = new PathString("/Account/Login/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
Run Code Online (Sandbox Code Playgroud)
在 httpd.conf 中,我想使用一台带有自定义端口的仅 SSL 主机,该端口提供来自 Kestrel 的内容。
Listen 34567
<VirtualHost *:34567>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
SSLEngine on
SSLProtocol all -SSLv3
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:!RC4+RSA:+HIGH:+MEDIUM:!LOW:!RC4
SSLCertificateFile certs/server.crt
SSLCertificateKeyFile certs/server.key
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
当我使用网址时 https://testserver1:34567时,它会重定向到http://testserver1:34567/Account/Login/?ReturnUrl=%2F,这当然会给出Bad Request。如果我通过将其更改为 https 来更正 url,那么之后一切都会正常工作。
我怎样才能使它始终重定向到 https url?
要在 ubuntu 上使用 apache2 反向代理:
<VirtualHost test.com:80>
ProxyPreserveHost On
ProxyRequests On
ServerName test.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/test
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /login http://127.0.0.1:8080/login
ProxyPassReverse /login http://127.0.0.1:8080/login
ProxyPass /api http://127.0.0.1:8080/api
ProxyPassReverse /api http://127.0.0.1:8080/api
Run Code Online (Sandbox Code Playgroud)
我有 apache2 错误
(111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8080 (127.0.0.1) failed
AH00959: ap_proxy_connect_backend disabling worker for (127.0.0.1) for 60s
Run Code Online (Sandbox Code Playgroud)
谢谢。
我有一个带有ARR 3.0 和 URL 重写模块 2.1 的IIS10 服务器,它充当其他几个 Web 服务器的反向代理。其他服务器在不同的端口上运行,因此 IIS10 服务器在端口 80 上提供“友好 URL”。 URL 重写用于将请求传递给后端服务器。
Jenkins就是这样的服务器之一。
Jenkins 有一条警告消息,告诉您反向代理是否配置良好(更多详细信息请参见此处),并且此警告消息帮助我找到了反向代理中的问题。
问题是 URL 重写正在对我的 URL 进行解码和编码,当它们到达 Jenkins 时,它们与浏览器请求的不同。
例子:
URL重写规则:
<rule name="Jenkins Rewrite" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*jenkins.mydomain.*" />
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Rewrite" url="http://localhost:8080/{R:1}" appendQueryString="true" />
<serverVariables>
<set name="HTTP_X_FORWARDED_HOST" value="{HTTP_HOST}" />
<set name="HTTP_X_FORWARDED_SCHEMA" value="https" />
<set name="HTTP_X_FORWARDED_PROTO" value="https" />
</serverVariables>
</rule>
Run Code Online (Sandbox Code Playgroud)
发送以下 URL 时:
我注意到编码字符在触发规则之前被解码,使得 {R:1} 看起来像这样:
/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https:/jenkins.mydomain/manage/
经过一番研究,我发现我可以使用 …
我想将 nginx 配置为反向代理,以将 HTTP 请求转发到外部 Cloud-API。这个 nginx 但我收到连接拒绝错误。
29 09:19:02 [error] 7#7: *2 connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: 10.0.2.2, request: "GET /apiv1/endpoint HTTP/1.1", upstream: "https://0.0.0.0:443/apiv1/endpoint", host: "localhost:8080"
Run Code Online (Sandbox Code Playgroud)
当然,我将上面(外部云的)ip替换为0.0.0.0
但我认为这就是问题所在。nginx 解析云主机的 ip,并将上游 url 替换为 ip 地址。但如果没有主机名,云主机就不知道将其站点上的请求重定向到哪里。
只是猜测......因为我也无法使用curl或postman向端点(以ip作为主机)发出请求。但有了 url 就可以了。
我的 nginx.conf
upstream cloudapi {
here-comes-the-cloud-url.com:443;
}
server {
listen 8080 default_server;
server_name localhost; #
location ^~ /apiv1/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_cache_bypass …Run Code Online (Sandbox Code Playgroud) 我正在用来docker-compose运行一个项目的基础设施,其中一部分包括 ELK 堆栈。我使用nginx作为反向代理kibana(除其他外,使用 LetsEncrypt 作为 CA 来处理 SSL)。
当我尝试通过访问 kibana 实例时,https://my.host.com/kibana我得到了一个JSON编码的 404 页面。我还在 kibana 日志中收到大量错误(见下文)。我尝试过修改server.host、server.basePath、server.rewriteBasePath、 nginx 的proxy_redirect(将其设置为off)。没有什么真正有帮助。任何帮助将非常感激。
这是我的kibana.yml:
elasticsearch.hosts: ["http://elasticsearch:9200"]
logging.dest: stdout
server.host: kibana
server.basePath: /kibana
server.rewriteBasePath: true
Run Code Online (Sandbox Code Playgroud)
这是我的相关部分nginx.conf:
location /kibana {
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;
proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
proxy_pass http://kibana:5601/;
proxy_read_timeout 90;
proxy_redirect http://kibana:5106 …Run Code Online (Sandbox Code Playgroud)