从主机计算机到达Django服务器的流浪者

2024-05-19 06:21:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用puphpet配置器设置了一个vagrant虚拟机,我安装了许多编程语言,包括PHP、python、ruby等。我为PHP项目安装了apache2和{},但它的{}我确实需要启动并运行。以下是配置文件中定义网络IP和主机名的部分:

            machines:
                vflm_zpwmfbk4aw05:
                    id: machine1
                    hostname: machine1.puphpet
                    network:
                        private_network: 192.168.56.101
                        forwarded_port:
                            vflmnfp_pjysbxl944a0:
                                host: '9346'
                                guest: '22'
                    memory: '2000'
                    cpus: '1'

当我vagrant up然后将主机浏览器指向192.168.56.101时,我得到一个空白屏幕。这意味着它连接到某个东西,否则我会得到一个404屏幕。在

我读到要从主机访问django服务器,需要运行以下命令:

^{pr2}$

但是当我把我的浏览器指向192.168.56.101:8000,我得到了404屏幕。在

以下是/etc/hosts文件中的内容:

127.0.0.1       machine1.puphpet        machine1
127.0.0.1       localhost
127.0.1.1       vagrant.vm      vagrant
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.3.3     myhost.dev

我手动添加了最后一行192.168.3.3 myhost.dev,因为我决定更改默认安装的设置,但它不起作用。在

接口文件如下:

$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp
pre-up sleep 2
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto enp0s8
iface enp0s8 inet static
      address 192.168.56.101
      netmask 255.255.255.0
#VAGRANT-END

apache2会与djangos服务器冲突吗?有没有一种方法可以确切地知道虚拟机中有哪些IP和端口可用?在


Tags: thelocalhostauto屏幕etcnetworkinterfacesphp
1条回答
网友
1楼 · 发布于 2024-05-19 06:21:54

我想出来了。一切都是关于端口转发。我安装的这个虚拟机有错误的端口转发设置:

enter image description here

主机端口为7280,来宾端口为22。这意味着我必须在端口22上运行VMs django服务器,并将主机浏览器指向端口7280。这不起作用,因为端口22是保留的,所以我无法在它上运行django服务器。解决方案是添加一个额外的端口转发规则。8000可以。因此,将来宾端口和主机端口都设置为8000,我可以在端口8000上运行服务器,然后通过端口8000的主机访问它。在

相关问题 更多 >

    热门问题