To prepare

  • When purchasing an Elastic Cloud Server (ECS), you can purchase an Elastic Cloud Server based on your system, configuration, and region requirements. Save the name and password of the successfully purchased instance. CentOS 8.1.1911 (reference)
  • A static page

    Static resources that you need to deploy. Such as:

  • The secure terminal Xshell is the most common Linux terminal emulation software. It supports SSH, SFTP, TELNET, RLOGIN, and SERIAL. Of course, the rest is pretty much the same. You can do whatever you like. If you are not familiar with the commands used to transfer resources between the local and server, you are advised to use WinSCP. It is an OPEN source SSH graphical SFTP client in Windows and supports the SCP protocol. You can copy files directly or edit them, which is very convenient.

Server Configuration

Add a security group. Configure port 80

Port 80 on a newly purchased server is disabled by default and needs to be manually configured. Log in to the cloud server website and go to the console to find the security group and click Create Security Group:

Configure as follows (inbound direction) :

Server environment

If you can access the security group based on the external IP address of the server after the security group is configured, you can directly see static resource configuration. If not, read on:

Viewing Port 80

netstat -tlnp
Copy the code
  1. If port 80 is not found in the list, install Nginx on the server:

Install Nginx

Nginx relies on the following three packages, please install as needed, the server may already exist.

yum install openssl
yum install zlib
yum install pcre
Copy the code

Install Nginx dependency libraries

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Copy the code

Install Nginx

yum install nginx
Copy the code

Start the Nginx

service nginx start
Copy the code
  1. If port 80 has been started (or the command is executed again), but the port cannot be accessed, check the firewall
firewall-cmd --state
Copy the code

Check whether the firewall is started. To avoid firewall interception, simply turn off the firewall (potentially risky)

service firewalld stop
Copy the code

It is recommended to open port 80:

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
firewall-cmd --permanent --add-port=80/tcp
Copy the code

At this point, you should be able to access the Nginx welcome page when accessing external IP addresses.

Static Resource Configuration

The Nginx welcome page is the default page, so it’s very easy to access our own page:

The project is copied to the server

Command:

SCP Local file address root@public network address: the address saved on the public networkCopy the code

Or use WinSCP to copy local files directly to a directory on the server.

Modify the Nginx configuration file nginx.conf

server {
    listen 80; Server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root /path/... ; The corresponding project address index index.html; Home page}}Copy the code

Reload the configuration file:

Nginx - s reloadCopy the code

Related commands, available for your own use:

Restart: nginx -s reopen: nginx -s stop Tests whether the configuration file is normal: nginx -t Forcibly closes: pkill nginxCopy the code

Refresh again and you can see your own page!