Nginx brief installation and configuration example analysis

PHPz
Release: 2023-05-18 15:34:15
forward
971 people have browsed it

1. Files required for nginx installation

1), nginx-1.2.8.tar.gz

2), openssl-1.0.1g.tar .gz

3), pcre-8.31.tar.gz

4), zlib-1.2.7.tar.gz

The download addresses of the above installation packages are available normally. , since I am using the installation package of the above version, the following installations are based on this.

2. Linux machine configuration environment

2.1.java environment

$java -version
java version "1.8.0_45"
java(tm) se runtime environment (build 1.8.0_45-b14)
java hotspot(tm) 64-bit server vm (build 25.45-b02, mixed mode)
Copy after login

2.2.Hardware configuration

Nginx brief installation and configuration example analysis

3. Installation steps

3.1. Unzip the installation package

Enter the nginx installation directory and unzip openssl-1.0.1g.tar.gz and pcre respectively -8.31.tar.gz, zlib-1.2.7.tar.gz, nginx-1.2.8.tar.gz four tar packages, execute the command tar -zxvf xxxx.tar.gz, where xxxx is the package name.

Nginx brief installation and configuration example analysis

After decompression:

Nginx brief installation and configuration example analysis

3.2. Compile the installation package

First compile the 3 required Library file packages: openssl-1.0.1g, pcre-8.31, zlib-1.2.7.

Compile openssl-1.0.1g, enter the file directory, and execute the following commands in sequence:

$./config$make$make install

Normal installation result:

Nginx brief installation and configuration example analysis

Compile pcre-8.31, enter the file directory, and execute the following commands in sequence:

$./config
$make
$make install
Copy after login

Normal installation result:

Nginx brief installation and configuration example analysis

Compile zlib-1.2.7, enter the file directory, and execute the following commands in sequence:

$./configure
$make
$make install
Copy after login

Normal installation results:

Nginx brief installation and configuration example analysis

Next, Compile the nginx installation package, enter the file directory, and execute ./configure. You need to specify the installation directory –prefix=/opt/nginx/nginx and the path of the corresponding library file

sudo ./configure --prefix=/opt/nginx /nginx --with-openssl=/opt/nginx/openssl-1.0.1g --with-pcre=/opt/nginx/pcre-8.31 --with-zlib=/opt/nginx/zlib-1.2.7

Next, compile and install.

Copy code The code is as follows:

sudo ./configure --prefix=/opt/nginx/nginx --with-openssl=/opt/nginx/openssl-1.0.1g --with -pcre=/opt/nginx/pcre-8.31 --with-zlib=/opt/nginx/zlib-1.2.7

Next, compile and install.

$make
$make install

Nginx brief installation and configuration example analysis

At this point, the nginx installation is completed.

3.3. Start nginx

Enter the nginx installation directory/opt/nginx/nginx/sbin and execute ./nginx to start the service.

[dddd.et15sqa /opt/nginx/nginx/sbin]

$sudo ./nginx

View the service process after startup:

$ps aux|grep nginx
root 2295 0.0 0.0 28264 804 ? ss 23:30 0:00 nginx: master process ./nginx
nobody 2296 0.0 0.0 28660 1356 ?      s   23:30 0:00 nginx: worker process
125233 2411 0.0 0.0 113720 1012 pts/0 s 23:31 0:00 grep nginx

Open nginx default homepage:

Nginx brief installation and configuration example analysis

#Service installation and startup OK!

4. Port forwarding

You need to forward port 80 to the tomcat homepage running in the server, and its port is 8080.

tomcat home page:

Nginx brief installation and configuration example analysis

## Configure the nginx.conf file of nginx as follows:

server {
    listen    80;
    server_name 127.0.0.1;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
      #root  html;
      #index index.html index.htm;
      proxy_set_header host $host;
      proxy_set_header x-real-ip $remote_addr;
      proxy_set_header x-forwarded-for $remote_addr;
      proxy_pass http://127.0.0.1:8080;
    }
Copy after login
Restart the nginx service, ./nginx -s reload

At this time, you can access port 80, but it actually jumps to the service of port 8080.

Nginx brief installation and configuration example analysis

The above is the detailed content of Nginx brief installation and configuration example analysis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!