Use Nginx under Linux

1. gcc installation

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

yum install gcc-c++

2. PCRE pcre-devel Installation
PCRE (Perl Compatible Regular Expressions) is a Perl library, including 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. pcre-devel is a secondary development library developed using pcre. Nginx also needs this library. command:

yum install -y pcre pcre-devel

3. zlib installation The
zlib library provides a variety of compression and decompression methods. Nginx uses zlib to gzip the contents of the http package, so you need to install the zlib library on Centos.

yum install -y zlib zlib-devel

4. OpenSSL installation
OpenSSL is a powerful secure socket layer cryptographic library, including the main cryptographic algorithms, commonly used key and certificate package management functions and SSL protocol, and provides a wealth of applications for testing or other purposes.
nginx not only supports the http protocol, but also supports https (that is, transmits http on the ssl protocol), so you need to install the OpenSSL library in Centos.

yum install -y openssl openssl-devel

Official website download

1. Download the .tar.gzinstallation package directly at https://nginx.org/en/download.html

2. Use the wgetcommand to download (recommended).

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


Unzip

Still a direct command:

tar -zxvf nginx-1.10.1.tar.gz 

cd nginx-1.10.1 


Configuration

 1. Use the default configuration

./configure



Compile and install

makemake install

Find the installation path:

whereis nginx

 

 

Start and stop nginx

cd /usr/local/nginx/sbin/./nginx ./nginx -s stop./nginx -s quit./nginx -s reload

./nginx -s quit: The stop step in this way is to stop after the nginx process has finished processing the task.
./nginx -s stop: This method is equivalent to finding the nginx process id and then using the kill command to forcefully kill the process.

Query the nginx process:

 

ps aux | grep nginx

 

Restart nginx

1. Stop before starting (recommended):
Restarting nginx is equivalent to stopping before starting, that is, executing the stop command first and then the start command. as follows:

./nginx -s quit./nginx

2. reload the configuration file:
After modifying the configuration file nginx.conf ngin x, to want a profile take effect need to restart nginx, use -s reloadwithout first stopping ngin x nginx restart to take effect in nginx configuration information as follows:
. / nginx -s reload

After successful startup, you can see this page in the browser:

 

Auto boot

That is, just rc.localadd the startup code.

vi /etc/rc.local

Add a line to  /usr/local/nginx/sbin/nginx
set the execution authority:

chmod 755 rc.local

 

At this point, nginx is installed, and start, stop, and restart operations are also completed. Of course, you can also add it as a system service, I will not demonstrate it here.

 

Let's start using the
simulated domain name access with Tomcat
to create the domain name
C: \ Windows \ System32 \ drivers \ etc \ hosts file in the host file of this machine

192.168.179.9 sf.com


Modify the Nginx configuration file nginx.conf
 server {
        listen 80; // here
        server_name 192.168.179.9:8091;//here
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root html; // here
            index  index.html index.htm;
            proxy_pass  http://192.168.179.9:8091 ; // here
        }
 
        #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;
        }
 


At this time, if you output sf.com in the local browser 

You should jump to the port 8091 bound to the tomcat bound to the nginx service of 179.9

 

Guess you like

Origin www.cnblogs.com/YinXuanZhiZhi9/p/12719162.html