如何在服务器上安装和配置Web服务器?
美国、香港服务器
如何在服务器上安装和配置Web服务器?
05-04 来源:
服务器安装配置 Web 服务器(两种主流:Nginx / Apache)
给你最简单、可直接复制执行的完整教程,CentOS / Ubuntu 都有。
一、先选一种
Nginx:性能强、占用低、现在主流,推荐装这个
Apache:老牌稳定,适合老旧网站
一、Ubuntu 安装 Nginx
1. 安装
bash
运行
sudo apt update
sudo apt install nginx -y
2. 启动开机自启
bash
运行
systemctl start nginx
systemctl enable nginx
3. 放行防火墙端口
bash
运行
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
4. 测试
浏览器输入 服务器 IP,看到 Nginx 默认页面就装好了。
网站根目录
plaintext
/var/www/html
把网站代码放这里即可。
二、CentOS 安装 Nginx
1. 安装
bash
运行
yum install nginx -y
2. 启动自启
bash
运行
systemctl start nginx
systemctl enable nginx
3. 防火墙放行
bash
运行
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
网站根目录
plaintext
/usr/share/nginx/html
三、安装 Apache(可选)
Ubuntu
bash
运行
sudo apt install apache2 -y
systemctl start apache2
systemctl enable apache2
CentOS
bash
运行
yum install httpd -y
systemctl start httpd
systemctl enable httpd
四、基础配置说明
网站文件放根目录,直接访问 IP 就能打开
配置文件位置
Nginx:/etc/nginx/nginx.conf
Apache:/etc/httpd/conf/httpd.conf
后续可以配置:
域名绑定
SSL 证书 HTTPS
伪静态、缓存优化
限制 IP、防攻击
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快