[英]Vagrant and NGINX only works on ports other than 80
For the purpose of this post, I am using Vagrant to launch NGINX (through Docker, but that is not important I don't think). 出于本文的目的,我正在使用Vagrant(通过Docker启动NGINX),但这并不重要,我认为这并不重要。
My Vagrant looks like the following: 我的无业游民如下所示:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
#Assign Box and VM Properties
config.vm.box = "ubuntu/trusty64"
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 2
end
# Network
config.vm.network "forwarded_port", guest:80, host: 80 #--> DOESN'T WORK localhost
config.vm.network "forwarded_port", guest:80, host:8391 #--> WORKS localhost:8391
# Provision
config.vm.provision :shell, inline: "sudo apt-get update"
config.vm.provision :docker
end
The goal is to be able to hist NGINX on localhost
and not localhost:8391
目标是能够在
localhost
而不是localhost:8391
上对NGINX进行历史记录localhost:8391
I KNOW that NGINX is listening on 80 because of the mapping, and from running CURL within Vagrant. 我知道NGINX由于映射以及在Vagrant中运行CURL而正在监听80。
You can use setcap to enable to use ports under 1024 for non-root users for specific binaries. 您可以使用setcap为非root用户启用1024以下端口的特定二进制文件。
This only works under Linux and must be applied to the Vagrant box, to use Port 80 inside the box, and your host, to use Port 80 on your host. 这仅在Linux下有效,必须将其应用于“ Vagrant”框,以使用该框内的端口80,以及您的主机,以使用主机上的Port 80。
You need the package libcap2-bin, eg with apt: 您需要软件包libcap2-bin,例如,带有apt:
Afterwards NGINX is allowed to use Port 80 inside the box as user vagrant. 之后,NGINX被允许作为用户游民使用盒子内的端口80。 Now enable setup for Vagrant on your host.
现在,在主机上启用Vagrant的设置。
In general you can't bind to ports 1024 or under on the host when using Vagrant, unless you run it as root. 通常,除非使用root用户运行,否则您不能在主机上绑定到主机上的端口1024或以下端口。 (As with other apps, it's obviously not recommended to run Vagrant as root.)
(与其他应用程序一样,显然不建议以root身份运行Vagrant。)
As an alternative, if you don't need to connect to "localhost" specifically you could try setting up a private network so your Vagrant box has a separate IP address. 或者,如果您不需要连接到“本地主机”,则可以尝试建立专用网络,以便您的Vagrant框具有单独的IP地址。 See http://docs.vagrantup.com/v2/networking/private_network.html for more info.
有关更多信息,请参见http://docs.vagrantup.com/v2/networking/private_network.html 。 That should let you connect to port 80 on that IP fine.
那应该可以让您连接到该IP罚款的端口80。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.