Rate This Document
Findability
Accuracy
Completeness
Readability

Configuring the HTTPS and HTTP Functions

On CentOS 7.6 or CentOS 8.1, if Nginx 1.14.2 or Nginx 1.19.3 is installed using the mirror site RPM package, configure the HTTPS and HTTP functions of Nginx based on the installation path. For the HTTPS function, enable the HTTPS server module in the Nginx configuration file nginx.conf and set the correct certificate and key paths. For the HTTP function, configure the listening port.

Configuring HTTPS

For Nginx 1.14.2 or Nginx 1.19.3 installed using the mirror site RPM package on CentOS 7.6 or CentOS 8.1, replace /usr/local/nginx in the following command with /etc/nginx.

  1. Run the following command to open the nginx.conf file:
    1
    vim /usr/local/nginx/conf/nginx.conf
    
  2. Press i to enter the insert mode and modify the file as follows:
    • Change #user nobody; to user root;.
    • Delete all number signs (#) from the # HTTPS server module.
    • In the # HTTPS server module, change listen 443 ssl; to listen 20000 ssl;.
    • In the # HTTPS server module, change ssl_certificate cert.pem; to ssl_certificate /usr/local/nginx/server_2048.crt;.
    • In the # HTTPS server module, change ssl_certificate_key cert.key; to ssl_certificate_key /usr/local/nginx/server_2048.key;.

    File before modification:

    #user  nobody;
    ...
    # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}

    File after modification:

    user  root;
    ...
    # HTTPS server
        #
        server {
             listen       20000 ssl;
             server_name  localhost;
             ssl_certificate      /usr/local/nginx/server_2048.crt;
             ssl_certificate_key  /usr/local/nginx/server_2048.key;
             ssl_session_cache    shared:SSL:1m;
             ssl_session_timeout  5m;
             ssl_ciphers  HIGH:!aNULL:!MD5;
             ssl_prefer_server_ciphers  on;
             location / {
                 root   html;
                 index  index.html index.htm;
             }
         }
  3. Press Esc, type :wq!, and press Enter to save the file and exit.

Configuring HTTP

  1. Run the following command to open the nginx.conf file:

    For Nginx installed using the mirror site RPM package on CentOS 7.6 or CentOS 8.1, replace /usr/local/nginx in the following command with /etc/nginx.

    1
    vim /usr/local/nginx/conf/nginx.conf
    
  2. Press i to enter the insert mode and modify the file as follows:
    • Change #user nobody; to user root;.
    • In the http module, change listen 80; to listen 10000;.

      If you install Nginx 1.14.2 (1.19.3) on CentOS 8.1 (7.6) in RPM mode, modify the listen port of the HTTP function in the /etc/nginx/conf.d/default.conf file.

    File before modification:

    #user  nobody;
    ...
    
    http {
        include       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  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
         }
    }

    File after modification:

    user  root;
    ...
    http {
        include       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  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        server {
            listen       10000;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
         }
    }
    ...
  3. Press Esc, type :wq!, and press Enter to save the file and exit.