Vagrant,Centos7,Nginx,Uwsgi,Django。 SSH + Nginx连接重置,然后连接被拒绝

问题描述 投票:0回答:1

版本

VirtualBox Version: 6.0.0 ( I think )    
Vagrant Version: 2.2.3    
CentosBox: "centos/7"    
Nginx Version: 1.16.1   
uWSGI Version: 2.0.18   
Django Version: 2.2.1   

背景

我有两个正在运行的无聊的盒子,一个测试和一个产品。唯一的区别是IP和核心数量。我已经设置了两者,所以我可以直接将它们放入ssh,而不必先放入主机,然后运行“ vagrant ssh”

一般问题

生产版本将随机地将我引导出ssh(通过IP端口22重置连接),然后我将拒绝连接。如果我先进入主机,然后再进入“ vagrant ssh”,但仍然可以进入,一切似乎都很好,我什至仍可以ping通网络上的其他计算机。但是我无法从主机外部访问它,这同样适用于chrome上的Nginx服务器(IP拒绝连接。)

问题有时会在几分钟之内解决,但是大多数情况下需要“无用的销毁”和“无用的--provision” /重新创建该框。我偶尔也会从主机和测试盒中退出,但是在通过VPN工作后(即使是处于测试中的Nginx服务器),我仍然可以从外部进行访问,并且有时也会从中退出。好吧,但是当我注意到

时我可以重新连接

VagrantFile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Please don't change it unless you know what you're doing.
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.hostname = "DjangoProduction"
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  config.vm.network "public_network", ip: "IP"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  config.vm.synced_folder "./", "D:/abcd", type: "sshfs", group:'vagrant', owner:'vagrant'

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |v|
    v.name = "DjangoProduction"

    # test has these two commented out
    v.memory = 6000
    v.cpus = 4
  end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  ## Keys
  ### For SSH directly into the Box
  # Work Laptop Key
  config.vm.provision "file", source: ".provision/keys/work.pub", destination: "~/.ssh/work.pub"
  config.vm.provision "shell", inline: "cat ~vagrant/.ssh/work.pub >> ~vagrant/.ssh/authorized_keys"
  # Personal Laptop Key
  config.vm.provision "file", source: ".provision/keys/msi.pub", destination: "~/.ssh/msi.pub"
  config.vm.provision "shell", inline: "cat ~vagrant/.ssh/msi.pub >> ~vagrant/.ssh/authorized_keys"
  ##

  required_plugins = %w( vagrant-sshfs )
  required_plugins.each do |plugin|
      exec "vagrant plugin install #{plugin};vagrant #{ARGV.join(" ")}" unless Vagrant.has_plugin? plugin || ARGV[0] == 'plugin'
  end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  config.vm.provision :shell, path: ".provision/boot.sh"
end

boot.sh

# networking
sudo yum -y install net-tools

ifconfig eth1 IP netmask 255.255.252.0
route add -net 10.1.0.0 netmask 255.255.252.0 dev eth1
route add default gw 10.1.0.1

# I manually set the gateway so It can be accessed through VPN

## install, reqs + drop things to places - gonna leave all that out

错误消息

Django

这个问题在本周早些时候开始出现,django向我发送了错误电子邮件说。它总是随机URL,没有一致性

OperationalError at /
(2003, 'Can\'t connect to MySQL server on \'external-ip\' (110 "Connection timed out")')

我以前每隔一天收到这封电子邮件,却没有引起注意,但目前每天至少要发送20封给我,而且该网站几乎无法使用-速度真的很慢,或者出现了Chrome错误:'ERR_CONNECTION_TIMED_OUT'或' ERR_CONNECTION_REFUSED'或'ERR_CONNECTION_RESET'..可以正常使用一个小时,然后一切都扑向风扇我原本以为这是db或uwsgi或django的问题,但是昨天与之合作时,我意识到与超时和被ssh踢出局限相关。

Chrome(可能不相关+另一个问题)] >>

此错误在生产和测试时都会弹出。我只能在两个页面上一致地在一个页面上重新创建它,并且加载它需要大约2分钟才能最终引发错误(这也不是要求很高的页面),而其他页面也可以工作。生产将在其他页面上随机产生此错误,然后在整个站点上显示ERR_CONNECTION_REFUSED(测试不这样做,两个页面都存在问题,但不会使整个站点崩溃。 )

GET https://IP/static/css/bootstrap.min.css     
net::ERR_CONNECTION_RESET 200 (OK)

有时在此错误之后,还会有其他CSS /媒体文件显示ERR_CONNECTION_REFUSED。

# Always bootstrap.min.css ERR_CONNECTION_RESET 200 (OK) Before

GET https://IP/static/media/favicon/favicon.ico 
net::ERR_CONNECTION_REFUSED

Nginx服务器设置

(我没有更改nginx.conf)
upstream django {
  server unix:///vagrant/abcd.sock;
}

server{
  listen  8080;
  return 301 https://$host$request_uri;
}
server{
  charset utf-8;
  listen 443 ssl;

  ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
  ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

  location / {
    uwsgi_pass  django;
    include /vagrant/project/uwsgi_params;
    uwsgi_read_timeout 3600;
    uwsgi_ignore_client_abort on;
  }

  location /static {
    alias /vagrant/static;
  }

  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root /vagrant/templates/core;
  }
}

使用的UWSGI命令

uwsgi --socket abcd.sock --module project.wsgi --chmod-socket=664 --master --processes 8 --threads 4 --buffer-size=65535 --lazy

Nginx错误日志

没事。

消息文件

仅在发生时显示'(110“连接超时”))转储

结论

我不知道如何,也没有错误日志。我认为这可能是VM本身的网络问题,因为为什么不能通过SSH从外部访问它?-我认为如果我发现所有内容都会恢复工作,请减去一页。真是太奇怪了,测试盒也不会发生这种情况,它们基本上是同一件事。在同一台主机上运行

对不起,如果到处都是,我认为包括所有可能相关的内容都比把东西遗漏了。。我也不是很清楚如何标记它,所以希望它还不错。]

任何帮助,想法或一般方向都很好。

版本VirtualBox版本:6.0.0(我认为)流浪版本:2.2.3 CentosBox:“ centos / 7” Nginx版本:1.16.1 uWSGI版本:2.0.18 Django版本:2.2.1背景我有...

您是否可以测试行为,但注释“ config.vm.synced_folder ...”行?

django nginx ssh vagrant uwsgi
1个回答
0
投票

您是否可以测试行为,但注释“ config.vm.synced_folder ...”行?

© www.soinside.com 2019 - 2024. All rights reserved.