一、安装nginx:
1.若 nginx 未安装,配置本地 repo 源,在 root权限下执行 yum install nginx 安装 nginx。
[root@localhost nginx]# yum install nginx
2.查看nginx安装的版本 nginx -v
[root@localhost nginx]# nginx -v
3.如果yum install nginx 失败,则是centos默认库库里没有nginx,需要下载第三方yum源,这里推荐使用阿里云的yum源库。如果yum install nginx 成功,跳过第3步,直接去第4步。
解决方法:切换yum源库
配置yum源的步骤
a.移除默认的yum仓库,也就是删除 /etc/yum.repos.d/底下所有的.repo文件(踢出国外的yum源)
a.配置yum源,找到阿里云的官方镜像源地址 https://opsx.alibaba.com/mirror
b.下载centos7的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
c.清空旧的yum缓存
yum clean all
d.生成新的yum仓库缓存(这个缓存来自于阿里云的yum仓库,便于加速软件下载)
yum makecache
e.配置一个第三方的 额外仓库源 (epel源),这个源的作用是,如果阿里云源找不到这个软件,就在这里找
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
4. 配置文件
将 /etc/nginx/nginx.conf 文件里代码全部删除,并将以下代码复制到此文件中,并保存退出。
user nginx;
worker_processes auto; # 建议设置为 core-1
error_log /var/log/nginx/error.log warn; # log 存放位置
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost; # 服务器名(url)
client_max_body_size 4G;
root /home/share; # centos上需要分享的目录
location / {
autoindex on; # 开启访问目录下层文件
autoindex_exact_size on;
autoindex_localtime on;
}
}
}
5.设置开机自动启动 systemctl enable nginx
启动 systemctl start nginx
查看状态 systemctl status nginx
重启 systemctl restart nginx
下图是查看的启动状态
二. 利用DDNSTO进行远程连接
1.进入DDNSTO官网并登录。官网链接为https://www.ddnsto.com/
a. 选择控制台
b. 添加设备选择 windows
主域名随便起
主机目标地址为 centos的ip地址
弹出下载窗口之后,
下载DDNSTO客户端下载地址, DDNSTO 下载后解压,执行ddnsto.exe
c. 配置ddnsto。将Token复制到下文中,点击保存
d. 远程连接
使用以下链接即可连接
https://dingshuai.tocmcc.cn:443