VPS远程访问配置指南
卡尔云官网
www.kaeryun.com
在虚拟专有服务器(VPS)上设置远程访问,可以让多用户同时访问网站,而无需登录服务器,以下是详细的配置步骤:
确保网站根目录权限正确
确保网站根目录权限为chmod 755
,只有管理员和root用户才能访问。
sudo chown -R www-data:www-data /var/www sudo chmod -R 755 /var/www
配置Apache安全策略
在Apache配置文件中,添加安全头,防止未授权访问。
<VirtualHost *:80> Require all granted <Directory /www root="www-data"> Option "AccessLog" on Option "ErrorLog" on <Option authz "SSSRSS"> Deny 80 from "localhost" except Deny 443 from "localhost" except Deny 80 from [::1] except www-data </Option> </Directory> </VirtualHost>
配置Nginx访问控制
在Nginx配置文件中,限制访问来源和端口。
<VirtualHost *:80> server_name yourdomain.com <Directory /www> AllowOverride All Options -MultiViews <Option authzSSR on> Deny from "localhost" Deny from 127.0.0.0:80 not www-data Deny from ::1:80 not www-data </Option> </Directory> </VirtualHost>
配置HTTPS
启用HTTPS,确保远程访问安全。
<VirtualHost *:443> server_name yourdomain.com <Directory /www> AllowOverride All <Option secure on> SSL Protocols TLSv1.2 cipher AES:128-GCM-SHA256 <Option ssi on> Off </Option> </Option> </Directory> </VirtualHost>
配置SSH远程访问
设置SSH端口并生成公私钥对。
sudo nano /etc/ssh/sshd_config [V2] ServerAliveInterval=30 AuthTunnel=0 <V2> Host www-data HostKeyChecking off User root Port 22 LocalIp 127.0.0.1,172.16.254.0/8 sshd_config file /etc/ssh/sshd_config </Host>
sudo ssh-keygen -t rsa -b 4096 sudo mv /root/.ssh/id_rsa www-data/id_rsa sudo nano /etc/ssh/sshd_config
配置浏览器访问插件
使用Chrome高级访问功能。
sudo apt install google-chrome-extreme sudo google-chrome-extreme --features=remote_access --enable
设置统一IP
确保所有设备访问同一个IP地址。
sudo dhclient -d www-data sudo dhclient -d www-data
测试配置
通过SSH或浏览器验证配置是否成功。
sudo ssh -i /root/.ssh/id_rsa www-data
https://www.yourdomain.com
通过以上步骤,您可以在VPS上轻松实现远程访问,定期检查配置,确保安全性和稳定性。
卡尔云官网
www.kaeryun.com