Alibaba cloud deployment 5. Domain name, DNS, nginx

Keywords: Javascript Nginx zlib DNS yum

domain name

Although you can visit your website directly through ip address, we seldom see that the website is accessed through ip address, and generally the website will provide domain name. The domain name is intuitive and easy to remember, and the resolved ip address can be changed without changing the domain name accessed by the user.

The domain name application can be purchased from wanwang. The state stipulates that the website can be accessed only after being recorded. The filing process that I follow in Alibaba cloud can fill in and upload the corresponding information in Alibaba cloud APP. The previous process needs to mail the curtain. Now it only needs to be operated online. Alibaba cloud's process is relatively fast, and will be submitted to the authority eventually. The authority's process needs to wait for a while (5-20 working days). My domain name from the beginning of filing to the success of filing, the process took about 2 weeks.

DNS

Domain name needs to be resolved to IP address, which is what DNS does. It can convert the domain name that is easy to manage and recognize into the digital IP address that the computer uses for interconnection communication, so as to route the user's access to the corresponding website or application server.

Similarly, I use alicloud's DNS resolution service. In the cloud DNS domain name console - domain name resolution, click Add domain name.

Add resolution again

The specific configuration is as follows

After configuration, the access domain name will resolve to the ip address filled in the record value.

nginx

Although the domain name resolves to the ip address (server), the default port is 80 (so please make sure that the security group rules are set for port 80 of the server. For details, please refer to the methods described in the previous article). What if the port we normally listen to is not 80? In fact, it's very simple. We just need to configure nginx.
Next, I will introduce how to install and use nginx on Alibaba cloud server.

install

Install PCRE PCRE devel and Zlib first
PCRE(Perl Compatible Regular Expressions) is a Perl library, including Perl compatible regular expressions library. The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on linux. pcre devel is a secondary development library developed with pcre. Nginx also needs this library. Order:

yum install -y pcre pcre-devel

Zlib library provides many ways to compress and decompress. nginx uses zlib to gzip the content of http package, so you need to install zlib library on Centos.

yum install -y zlib zlib-devel

Install GCC and OpenSSL

yum install gcc-c++
yum install -y openssl openssl-devel

Now we start to install nginx. Here I install version 1.14.0

wget -c https://nginx.org/download/nginx-1.14.0.tar.gz

Unzip and enter nginx directory

tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0

Use the default configuration of nginx

./configure

Compilation and installation

make
make install

Find the installation path:

[root@iZ8vbfhrv1vsbp44n9fdtoZ ~]# whereis nginx
nginx: /usr/local/nginx

Enter the sbin directory, and you can see that there is an executable file nginx, which can be executed directly. / OK.

[root@iZ8vbfhrv1vsbp44n9fdtoZ ~]# cd /usr/local/nginx
[root@iZ8vbfhrv1vsbp44n9fdtoZ nginx]# ls
client_body_temp  fastcgi_temp  logs        sbin       uwsgi_temp
conf              html          proxy_temp  scgi_temp
[root@iZ8vbfhrv1vsbp44n9fdtoZ nginx]# cd sbin
[root@iZ8vbfhrv1vsbp44n9fdtoZ sbin]# ls
nginx
[root@iZ8vbfhrv1vsbp44n9fdtoZ sbin]# ./nginx

Configure power on self start
Add the startup code in rc.local. Add a line / usr/local/nginx/sbin/nginx

vi /etc/rc.local

Set execution permission:

chmod 755 rc.local

To configure

nginx configuration file modification

vim /usr/local/nginx/conf/nginx.conf

Modify part of the original configuration file

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /opt/nodejs/blog-server/static/blog;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy to the blog server
    location /blog {
        proxy_pass http://0.0.0.0:3000;
    }
}

In this way, accessing the root path of port 80 will request the index.html file, and the request matching the / blog path will be forwarded to port 3000 of the local server.
After configuration, you can execute the command to check whether there is any error in the configuration

[root@iZ8vbfhrv1vsbp44n9fdtoZ conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

Finally, restart nignx

/usr/local/nginx/sbin/nginx -s reload

At this time, when you access the domain name, you will request the front and back resources according to the nginx configuration. Visit My website(http://www.readingblog.cn/#/b... Try it.

Posted by vikaspa on Sat, 02 Nov 2019 03:07:35 -0700