我希望能够通过 wifi 连接我的 Linux 电脑上的智能手机,随时随地访问存储在我的 Linux 电脑上的我自己的网站,以便能够测试我的网站。 我在互联网上进行了搜索,但我唯一能做的就是将手机连接到计算机,但不能访问存储的网站。
是否可以使计算机像个人服务器一样工作?
最佳答案
您需要安装服务器软件,获取 IP 和端口。
深入(假设您使用的是 ubuntu,使用 apache2 lamp 服务器):
1.安装软件:
安装 apache2(必需)、mysql(可选)和 php(可选):
sudo apt update
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php libapache2-mod-php
重新启动apache
sudo /etc/init.d/apache2 restart
2.将文件移至托管目录:
您想要通过拖放或 mv 命令将网站中的所有文件(可以保留子文件夹)移至/var/www/html
3.端口转发:
进入路由器设置,进入端口转发设置,然后将端口 80(HTTP) 指向计算机的 IP。
4.设置静态ip:
使用命令行打开/etc/network/interfaces 或使用 sudo nautilus 并找到它。添加以下行并替换 ():
iface (Ethernet or WiFi port) inet static
address (IP address you want on network but the first 3 numbers must be the same as the default gateway)
netmask 255.255.255.0
gateway (default gateway a.k.a router settings ip)
5.连接:
如果您的手机与站点位于同一网络,您可以通过网络浏览器连接到您之前创建的静态 IP。要从任何地方进行连接,请在 http://www.whatsmyip.org/ 等网站上找到您的外部 IP。并与任何网络浏览器连接。
关于linux - 在任何手机上查看存储在 Linux PC 上的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45885314/