问题描述
为了这篇文章的目的,我正在使用Vagrant发布NGINX(通过Docker,但这并不重要,我不认为)。
For the purpose of this post, I am using Vagrant to launch NGINX (through Docker, but that is not important I don't think).
我的流氓如下所示:
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
目标是能够在上组织NGINX localhost
而不是 localhost:8391
我知道NGINX正在听80,因为的映射,并从Vagrant中运行CURL。
I KNOW that NGINX is listening on 80 because of the mapping, and from running CURL within Vagrant.
推荐答案
您可以使用setcap启用1024以下的端口, root用户的特定二进制文件。
You can use setcap to enable to use ports under 1024 for non-root users for specific binaries.
这只能在Linux下工作,并且必须应用到Vagrant框中,使用框内的端口80和主机才能使用端口80你的主机。
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.
你需要libcap2-bin包,例如使用apt:
You need the package libcap2-bin, e.g. with apt:
- sudo apt-get install libcap2-bin
- sudo setcap cap_net_bind_service = + ep / path / to / nginx-binary
之后,NGINX被允许使用Box 80作为用户流氓。现在启用主机上的Vagrant设置。
Afterwards NGINX is allowed to use Port 80 inside the box as user vagrant. Now enable setup for Vagrant on your host.
- sudo setcap cap_net_bind_service = + ep / path / to / vagrant-binary
这篇关于Vagrant和NGINX仅适用于80以外的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!