我正在尝试排除服务器无法响应公共请求的原因。我正在运行 nginx,配置文件如下:
ngingx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
站点可用/生产.conf
upstream mip-production-backend {
server unix:///home/rails/apps/mip/production/shared/sockets/thin.0.sock;
server unix:///home/rails/apps/mip/production/shared/sockets/thin.1.sock;
server unix:///home/rails/apps/mip/production/shared/sockets/thin.2.sock;
server unix:///home/rails/apps/mip/production/shared/sockets/thin.3.sock;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80 default_server;
root /home/rails/apps/mip/production/current/public;
location / {
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
if (!-f $request_filename) {
proxy_pass http://mip-production-backend;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/rails/apps/mip/production/current/public;
}
我已经启动了 4 个连接到套接字的瘦服务器,如下所示:
RAILS_ENV=production bundle exec thin start --socket /home/rails/apps/mip/production/shared/sockets/thin.1.sock
我可以看到套接字在它们应该在的地方,我尝试删除一个并运行 wgethttp://本地主机,返回:
2018/03/14 10:23:34 [error] 184654#0: *1 connect() to unix:///home/rails/apps/mip/production/shared/sockets/thin.3.sock failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /login HTTP/1.1", upstream: "http://unix:///home/rails/apps/mip/production/shared/sockets/thin.3.sock:/login", host: "localhost"
仅当我删除了其中一个套接字时,此错误才会出现在日志中,因此它会按应有的方式读取它们。访问日志为:
27.0.0.1 - - [14/Mar/2018:10:23:34 +0000] "GET / HTTP/1.1" 302 99 "-" "Wget/1.15 (linux-gnu)"
127.0.0.1 - - [14/Mar/2018:10:23:34 +0000] "GET /login HTTP/1.1" 200 1231 "-" "Wget/1.15 (linux-gnu)"
127.0.0.1 - - [14/Mar/2018:10:29:40 +0000] "GET / HTTP/1.1" 302 99 "-" "Wget/1.15 (linux-gnu)"
127.0.0.1 - - [14/Mar/2018:10:29:40 +0000] "GET /login HTTP/1.1" 200 1231 "-" "Wget/1.15 (linux-gnu)"
127.0.0.1 - - [14/Mar/2018:10:29:46 +0000] "GET /login HTTP/1.1" 200 1231 "-" "Wget/1.15 (linux-gnu)"
该日志仅显示本地请求,当我远程访问公共 IP 时它不会注册。
我尝试搜索,但找不到任何关于如何让 nginx 响应访问 IP 地址而不是本地请求的建议。任何帮助都非常感谢
编辑:sudo netstat -tulpn 返回:
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1556/mysqld
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1605/redis-server 1
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 194492/nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1469/sshd
tcp 0 0 127.0.0.1:6392 0.0.0.0:* LISTEN 1429/redis-server 1
tcp6 0 0 :::22 :::* LISTEN 1469/sshd
答案1
事实证明,我访问的服务器无法直接访问公共请求,而是通过第二台服务器进行路由,而第二台服务器并没有像应该的那样将任何请求转发给 nginx