【发布时间】:2018-02-08 01:12:09
【问题描述】:
请帮我写配置。 它可以工作,但是当我转到位置 http://my.server.ru/pgadmin/ 时,它会重定向到 / 登录,并且 / 中没有位置名称。
server {
listen 80;
server_name my.server.ru;
error_log /home/user/error.log error;
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/django_app.sock;
}
location /pgadmin {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:5050/;
proxy_redirect http://127.0.0.1:5050 http://$host/pgadmin/;
}
location /static/ {
root /home/user/django_app;
expires 365d;
}
location /media/ {
root /home/user/django_app;
expires 365d;
}
location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
}
我不明白如何处理它。哪里需要改写?
更新: 卷曲的输出
* Trying xx.xx.xx.xx...
* TCP_NODELAY set
* Connected to my.server.ru (xx.xx.xx.xx) port 80 (#0)
> GET /pgadmin/ HTTP/1.1
> Host: my.server.ru
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Content-length: 0
< Location: https://my.server.ru/pgadmin/
<
* Curl_http_done: called premature == 0
* Connection #0 to host my.server.ru left intact
* Issue another request to this URL: 'https://my.server.ru/pgadmin/'
* Trying xx.xx.xx.xx...
* TCP_NODELAY set
* Connected to my.server.ru (xx.xx.xx.xx) port 443 (#1)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: CN=xxxxxx
* start date: Jul 31 11:42:00 2017 GMT
* expire date: Oct 29 11:42:00 2017 GMT
* subjectAltName: host "my.server.ru" matched cert's "my.server.ru"
* issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
* SSL certificate verify ok.
> GET /pgadmin/ HTTP/1.1
> Host: my.server.ru
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 302 FOUND
< Server: nginx/1.10.3 (Ubuntu)
< Date: Wed, 30 Aug 2017 12:51:49 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 236
< Location: http://my.server.ru/login?next=%2F
< Set-Cookie: pga4_session="c8e21d09-5d31-42e3-a4d5-a3ed87873a69!6KcWbhziK2zypWCzKTRyFLUdszI="; Expires=Thu, 31-Aug-2017 15:51:49 GMT; HttpOnly; Path=/
<
* Ignoring the response-body
* Curl_http_done: called premature == 0
* Connection #1 to host my.server.ru left intact
* Issue another request to this URL: 'http://my.server.ru/login?next=%2F'
* Found bundle for host my.server.ru: 0x55568d6af270 [can pipeline]
* Re-using existing connection! (#0) with host my.server.ru
* Connected to my.server.ru (xx.xx.xx.xx) port 80 (#0)
> GET /login?next=%2F HTTP/1.1
> Host: my.server.ru
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Content-length: 0
< Location: https://my.server.ru/login?next=%2F
<
* Curl_http_done: called premature == 0
* Connection #0 to host my.server.ru left intact
* Issue another request to this URL: 'https://my.server.ru/login?next=%2F'
* Found bundle for host my.server.ru: 0x55568d6affb0 [can pipeline]
* Re-using existing connection! (#1) with host my.server.ru
* Connected to my.server.ru (xx.xx.xx.xx) port 443 (#1)
> GET /login?next=%2F HTTP/1.1
> Host: my.server.ru
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: nginx/1.10.3 (Ubuntu)
< Date: Wed, 30 Aug 2017 12:51:49 GMT
< Content-Type: text/html
< Content-Length: 79
< X-Frame-Options: SAMEORIGIN
<
* Curl_http_done: called premature == 0
* Connection #1 to host my.server.ru left intact
未找到
在此服务器上找不到请求的 URL /login。
我们在这里看到重定向到 /
【问题讨论】:
-
将
proxy_redirect http://127.0.0.1:5050 http://$host/pgadmin/;更改为proxy_redirect http://127.0.0.1:5050/ http://$host/pgadmin/;。同时发布curl -vL http://my.server.ru/pgadmin/的输出 -
已将 chenges 发布到配置。完成,但我被重定向到根页面。
-
Okie,您似乎有更多配置,而您发布的配置只是其中的一部分。您的问题是您定义的块在监听 80 中,但是还有一个重定向到 https 的附加块,并且 https 块没有
/pgadmin。所以你得到一个 https 重定向,然后/pgadmin不存在所以你得到一个login重定向 -
不,我刚刚添加了 proxy_redirect http https;到我的配置。它的包我想我找到了注销重定向线程。我认为最好的方法是在这种情况下做子域? postgresql-archive.org/…
-
不确定,看看是否适合你
标签: nginx pgadmin nginx-location nginx-reverse-proxy