Example of how to configure nginx in centos server

Example of how to configure nginx in centos server

Download the secure terminal MobaXterm_Personal

First, download the secure terminal and connect to your public IP.

After the connection is successful, the display is as above.

Introduction to Nginx

Nginx is a lightweight web server and reverse proxy server. Compared with Apache and lighttpd, it has the advantages of less memory usage and higher stability. Its most common use is to provide reverse proxy services

After connecting to the server

Step 1: Install gcc gcc-c++

The command is:

yum install -y gcc gcc-c++

Step 2: Install the PCRE library

$ cd /usr/local/
$ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
$ tar -zxvf pcre-8.36.tar.gz
$ cd pcre-8.36
$ ./configure
$ make && make install

If an error is reported: configure: error: You need a C++ compiler for C++ support

Solution: yum install -y gcc gcc-c++

Step 3: Install SSL library

$ cd /usr/local/
$ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
$ tar -zxvf openssl-1.0.1j.tar.gz
$ cd openssl-1.0.1j
$ ./config
$ make && make install

Step 4: Install zlib library

$ cd /usr/local/
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ ./configure
$ make && make install

Step 5: Install nginx

$ cd /usr/local/
$ wget http://nginx.org/download/nginx-1.8.0.tar.gz
$ tar -zxvf nginx-1.8.0.tar.gz
$ cd nginx-1.8.0 
$ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
(Note: If you do not add --with-http_ssl_module: after configuring ssl: on in nginx.conf, the startup will report nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf exception)
$ make && make install

Start nginx

$ /usr/local/nginx/sbin/nginx

Step 6: Check whether the startup is successful

Open the browser and access the IP address of this machine. If the browser displays Welcome to nginx!, it means that Nginx has been installed and is running successfully.

Here are some things I encountered during this process:

When I reached step 6, the connection with the browser was unsuccessful and no response appeared, so I checked whether port 80 of the firewall was open.

The command is:

firewall-cmd --list-all Check port 80

firewall-cmd --zone=public --add-port=80/tcp If port 80 is not open, open port 80

firewall-cmd --reload Re-enable the firewall

Restart the nginx service again:

/usr/local/nginx/sbin/nginx –s reload

If you still cannot connect to this IP address, check whether the local connection is normal:

The command is:

curl localhost 

As shown in the picture, the local connection is successful, but the IP is inaccessible

Finally, I checked and found that it was because the Alibaba Cloud security group only opened ports 22 and 3389 for the new server, but not port 80.

Only these two port numbers are not enough. In order to connect to the server, port 80 needs to be opened.

Add configuration rules for security groups

Since we are using Alibaba Cloud, we can use Alibaba Cloud's security group operations to achieve the port opening effect.

After logging in to Alibaba Cloud, select in the following order: Cloud Server ECS->Security Group->Configuration Rules

There are currently three security group rules, namely 22, 3389 and ICMP protocols.

Then click Add Security Group Rules in the upper right corner.

Add port 80

As shown in the figure, only two changes are needed:

Port range: 21/21 means starting from 21 and ending at 21

Authorization object: 0.0.0.0/0 means all IP addresses can access this port

As shown in the figure, a new rule is added

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • CentOS+Nginx+PHP+MySQL detailed configuration (illustration)
  • CentOS 6.4 installation and configuration of LNMP server (Nginx+PHP+MySQL)
  • Install and configure Nginx on CentOS 7
  • CentOS+Nginx+PHP+MySQL standard production environment configuration method
  • How to install and configure Nginx on CentOS 6.3
  • Deploy nginx, php (including fastcgi), and virtual host configuration in CentOS 6.1 environment
  • Tutorial on configuring Nginx+Gunicorn+Python+Flask environment on CentOS
  • Compile, install and configure Nginx+PHP+MySql environment under Centos7
  • CentOS7 configuration Nginx support HTTPS access implementation solution
  • How to configure Nginx, MySql, and php-fpm on CentOS6
  • Detailed explanation of configuring Nginx auto-start based on CentOS 7
  • How to install Nginx in CentOS7 and configure automatic startup

<<:  A brief comparison of Props in React

>>:  Tutorial on configuring and changing passwords for the MySQL free installation version

Recommend

JavaScript to add and delete messages on the message board

This article shares a small example of adding and...

A brief discussion on the problem of forgotten mysql password and login error

If you forget your MySQL login password, the solu...

How to implement Ajax concurrent request control based on JS

Table of contents Preface Ajax serial and paralle...

About ROS2 installation and docker environment usage

Table of contents Why use Docker? Docker installa...

In-depth understanding of the seven communication methods of Vue components

Table of contents 1. props/$emit Introduction Cod...

How to view and clean up Docker container logs (tested and effective)

1. Problem The docker container logs caused the h...

svg+css or js to create tick animation effect

Previously, my boss asked me to make a program th...

A brief discussion on the specific use of viewport in mobile terminals

Table of contents 1. Basic Concepts 1.1 Two kinds...

Implementation steps for docker deployment of springboot and vue projects

Table of contents A. Docker deployment of springb...

Linux uses NetworkManager to randomly generate your MAC address

Nowadays, whether you are on the sofa at home or ...

Detailed explanation of Linux commands sort, uniq, tr tools

Sort Tool The Linux sort command is used to sort ...

MySQL query optimization: causes and solutions for slow queries

Friends who are doing development, especially tho...

HTML+CSS div solution when relative width and absolute width conflict

Div solution when relative width and absolute wid...

Vue example code using transition component animation effect

Transition document address defines a background ...