添加nginx仓库
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.norach.rpm
使用yum安装nginx
yum install nginx
配置nginx监听端口
vim /etc/nginx/conf.d/default.conf
在编辑这个配置文件时主要关注server下的listen字段和location字段下的root字段的值:
#配置文件内容大致如下:
server{
listen 9000;
server_name localhost;
location{
#默认访问的页面路径
root /usr/share/nginx/html;
index index.html index.htm;
}
......
}
将listen的值修改成服务器能被访问的端口,此处我将其设为9000
设置nginx启动用户
vim /etc/nginx/nginx.conf
编辑该文件的user的值,将其设置为当前用户启动nginx的用户名
开放防火墙对应端口
#设置开机自启动防火墙
systemctl enable firewalld.service
#启动防火墙
systemctl start firewalld
#查看防火墙状态
systemctl status firewlld
#开放对应端口
firewall-cmd --zone=public --add-port=9000/tcp --permanent
#重启防火墙
systemctl restart firewalld
#查看已开启的端口
firewall-cmd --list-ports
使用scp上传打包的项目文件
# scp用法:scp 打包好的本地文件的绝对路径 远程用户名@ip:对应的文件夹
# 例:
scp C:/Desktop/dist.zip root@192.168.216.133:/home/i/file
# 上传后于对应位置将其解压
unzip dist.zip
配置nginx访问路径
# 又来改这个配置文件了
vim /etc/nginx/conf.d/default.conf
# 将location下的root的值改为刚才解压的目录路径
location{
root /home/i/file;
...
}
重新加载nginx配置,重启nginx
# 重新加载nginx配置
nginx -s reload
# 查看nginx命令位置
whereis nginx
# nginx: /usr/sbin/nginx /....
# 重启nginx
/usr/sbin/nginx -s reopen
现在,使用浏览器访问远程服务器的对应端口就能看到自己写的页面辣!