部署 Nginx
      更新时间:2023-11-06 09:26:48
    
    
    
    
    
    
    
      
    
    
  本文介绍如何在云服务器上部署 Nginx 项目。
前提条件
已创建云服务器。
软件版本
本操作示例使用如下软件版本,在实际操作时,请以实际软件版本为准。
- 
操作系统:CentOS Stream 9 64bit 
- 
Nginx 版本:1.20.1 
操作步骤
安装 Nginx
- 
在云服务器列表,点击名称列点击 Web 终端图标,以 root 用户登录云服务器。 具体操作方法,请参见连接云服务器。 
- 
执行以下命令安装 Nginx。 # 安装 Nginx yum -y install nginx # 查看 Nginx 版本 nginx -v
- 
启动 Nginx 并设置开机启动。 systemctl start nginx systemctl enable nginx
- 
使用浏览器访问 http://云服务器的公网IP地址,显示如下页面,表示 Nginx 安装成功。  
验证 Nginx 服务
Nginx 的默认根目录是/usr/share/nginx/html,修改 html 下的 index.html页面,用来标识当前服务器的访问。
- 
执行以下命令打开 index.html文件。vi /usr/share/nginx/html/index.html
- 
按 i 进入编辑模式,修改文件内容。 在<body>标签后插入如下内容: # 在<body> 下方输入 <h1 style="padding:10px">Welcome to nginx test page!</h1> <p style="padding:10px;color:red"> This is <strong>vm1</strong>!</p>
- 
按 Esc,输入 :wq保存编辑。
- 
使用浏览器访问 http://云服务器的公网IP地址,页面显示如下字样,说明 Nginx 部署成功。