Alibaba Cloud Centos7 installs Nginx server to implement reverse proxy

1 Installation and configuration

1.1 Download

Download address https://nginx.org/en/download.html

The Nginx official website provides three types of versions.
Mainline version: Mainline is the version that Nginx is currently working on. It can be said that it is the development version.
Stable version: the latest stable version, the version recommended for use in the production environment
Legacy versions: the stability of the legacy old version Version

Log in to the Alibaba Cloud server, create a new nginx folder, and upload the file to the current directory to unzip it.

Shell>cd /usr/local/
Shell>mkdir nginx

 

Shell>tar -zxf nginx-1.14.0.tar.gz

1.1 Environmental Requirements

Nginx is developed in C language. It is recommended to run on linux. This tutorial uses Centos6.4 as the installation environment.

gcc

To install nginx, you need to compile the source code downloaded from the official website first, and the compilation depends on the gcc environment. If there is no gcc environment, you need to install gcc:,

Shell>yum install gcc-c++

PCRE

PCRE (Perl Compatible Regular Expressions) is a Perl library that includes a perl-compatible regular expression library. The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on linux.

Shell>yum install -y pcre pcre-devel

Note: pcre-devel is a secondary development library developed using pcre. nginx also requires this library.

zlib

The zlib library provides many ways to compress and decompress. nginx uses zlib to gzip the content of the http package, so the zlib library needs to be installed on linux.

Shell>yum install -y zlib zlib-devel

openssl

OpenSSL is a powerful secure socket layer cryptographic library, including major cryptographic algorithms, commonly used key and certificate encapsulation management functions and SSL protocols, and provides a wealth of applications for testing or other purposes.

Nginx supports not only the http protocol, but also https (that is, transmitting http over the ssl protocol), so you need to install the openssl library in linux.

Shell>yum install -y openssl openssl-devel

1.2 Compile and install

Step 1: Enter the nginx-1.14.0 folder. Use the configure command to create a makefile.

Shell>./configure

Step 2: (Skip this step, default) The parameter settings are as follows:

./configure \

--prefix=/usr/local/nginx \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/temp/nginx/client \

--http-proxy-temp-path=/var/temp/nginx/proxy \

--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \

--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \

--http-scgi-temp-path=/var/temp/nginx/scgi

 

Note: The temporary file directory is specified as /var/temp/nginx above, and the temp and nginx directories need to be created under /var

the fifth step:

Shell>make

Step 6

Shell>make install

2 Modify the tomcat port number

I used tomcat to publish the web before, the port number is 80, and now it is changed to port 8080

modify port

Shell>cd /usr/local/tomcat/apache-tomcat-7.0.85/conf
Shell>vim server.xml

Open port 8080

3 Nginx configuration, startup and shutdown

Upload static resources

3.1 Start

There is an sbin directory under the nginx directory, and an nginx executable program under the sbin directory.

Shell>./nginx

3.2 Close nginx

Close command: equivalent to find the nginx process kill.

Shell>c./nginx -s stop

Exit command:

Shell>c./nginx -s quit

It is recommended to use this command to close after the program is executed.

3.3 Dynamically loading configuration files

Shell>c./nginx -s reload

The configuration file can be updated without shutting down nginx.

3.4 Reverse proxy configuration

Detailed description link address:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324885750&siteId=291194637