我有一個作爲Web服務器由Nginx控制的Web應用程序。當它被配置如下,它的工作。打到http://192.168.33.10:9174/產生「需要402付款」Nginx可以作爲反向代理,但不會通過套接字將流量傳遞給Puma
# /etc/nginx/sites-enabled/myapp
server {
listen 9174;
server_name 127.0.0.1;
location /status {
stub_status on;
access_log off;
}
return 402;
}
它的工作原理。
然後我試圖讓它將流量轉發到Puma應用服務器,但失敗了。然後我設置了一堆代理如下:
# /etc/nginx/sites-enabled/myapp
upstream sqlitething {
server www.sqlite.org;
}
upstream hwacithing {
server www.hwaci.com;
}
upstream appthing {
#server unix:///home/deployer/myapp/shared/sockets/socktest.sock
server unix:/home/deployer/myapp/shared/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name 192.168.33.10;
location/{
proxy_pass http://sqlitething;
}
}
server {
listen 8080;
server_name 192.168.33.10;
location/{
proxy_pass http://hwacithing;
}
}
server {
listen 8099;
server_name 192.168.33.10;
location/{
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://appthing;
}
}
server {
listen 9175;
server_name 192.168.33.10;
return 402;
}
這裏是我的結果時,我打了瀏覽器的網址:
- http://192.168.33.10:80,它代理www.sqlite.org(預期) 。
- http://192.168.33.10:8080,它代理www.hwaci.com(預期)
- http://192.168.33.10:9175,返回HTTP 402(需要付款)消息(預期)
- http://192.168.33.10:8099想我重定向到https://appthing,但沒有發生(NOT預期)
套接字文件存在與權限如下:
srwxrwxrwx 1 deployer deployer 0 Jun 8 19:15 /home/deployer/myapp/shared/sockets/puma.sock
-------- UPDATE 6月8日5: 57 EST --------------------
我嘗試了失敗的網址如下:
$ curl -isL http://192.168.33.10:8099
HTTP/1.1 301 Moved Permanently
Server: nginx/1.1.19
Date: Wed, 08 Jun 2016 21:52:54 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Location: https://appthing/
Vary: Accept-Encoding
我試成功URL以下
$ curl -isL http://192.168.33.10:8080
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Wed, 08 Jun 2016 21:54:46 GMT
Content-Type: text/html
Content-Length: 1167
Connection: keep-alive
Vary: Host
Last-Modified: Wed, 13 Dec 2006 14:54:32 GMT
ETag: "88047-48f-4247d938f5a00"
Accept-Ranges: bytes
<html><head><title>Hwaci Homepage</title></head><body bgcolor="white">
<font size="7"><b>Hwaci</b></font><br>
...etc...
----- UPDATE 6月9日上午11時24分EST --------------
我在線加入
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
到連接到Unix套接字的端口8099的服務器/監聽塊。我得到了同樣的結果。
我後來去http://blog.honeybadger.io/how-unicorn-talks-to-nginx-an-introduction-to-unix-sockets-in-ruby/當他們指定成立了一個小插座服務器,但與
unix:///home/deployer/myapp/shared/sockets/socktest.sock
插座然後我修改了nginx.conf所以它不會守護進程和錯誤會去到標準輸出。
daemon off;
error_log /dev/stdout info;
然後我nginx的跑了作爲
> sudo nginx -c nginx.conf
當我跑到捲曲擊中的nginx /插座組合,我得到這個:
$ curl -isL http://192.168.33.10:8099
HTTP/1.1 502 Bad Gateway
Server: nginx/1.1.19
Date: Thu, 09 Jun 2016 15:13:57 GMT
Content-Type: text/html
Content-Length: 173
Connection: keep-alive
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.1.19</center>
</body>
</html>
nginx的日誌是這樣的:
2016/06/09 15:13:34 [notice] 9885#0: start worker process 9889
2016/06/09 15:13:49 [info] 9886#0: *1 client 192.168.33.1 closed keepalive connection
2016/06/09 15:13:57 [crit] 9886#0: *3 connect() to unix:/home/deployer/myapp/shared/sockets/socktest.sock failed (13: Permission denied) while connecting to upstream, client: 192.168.33.1, server: 192.168.33.10, request: "GET/HTTP/1.1", upstream: "http://unix:/home/deployer/myapp/shared/sockets/socktest.sock:/", host: "192.168.33.10:8099"
2016/06/09 15:13:57 [info] 9886#0: *3 client 192.168.33.1 closed keepalive connection
----- 6月9日結束更新--------- ---------- - - - - - - - ---
彪馬進程正在運行
[email protected]:/etc/nginx/sites-enabled$ ps -ef | grep puma
deployer 21319 1 0 19:15 ? 00:00:00 puma 2.16.0 (unix:///home/deployer/myapp/shared/sockets/puma.sock) [20160608191112]
deployer 21322 21319 0 19:15 ? 00:00:09 puma: cluster worker 0: 21319 [20160608191112]
deployer 21326 21319 0 19:15 ? 00:00:10 puma: cluster worker 1: 21319 [20160608191112]
我配置所述上游彪馬作爲各種配置指南指定。我究竟做錯了什麼?
有沒有辦法查看Puma進程是否真正在爲我的Web應用程序提供服務?
有沒有辦法使用curl或wget和通過Unix套接字來訪問Puma進程(unix:/home/deployer/myapp/shared/sockets/puma.sock)?
你是什麼意思的「試圖重定向,但沒有發生」?當你點擊'http://192.168.33.10:8099 /'url時,究竟發生了什麼? – Roman
網絡瀏覽器將我重定向到https:// appthing。 –
你的意思是說,'https:// appthing /'字面意思? – Roman