Linux system installs and configures nginx to realize multiple services and the same port

Posted by ragedigital on Mon, 07 Mar 2022 02:43:29 +0100

 

The basic requirement is that the project should achieve concurrency. Because of the deep learning framework, tornado service cannot start the service through multiple processes in the following ways,

http_server.bind(port)
http_server.start(n)   #n is the number of processes

Therefore, seek other ways to achieve concurrency. Services are provided through the docker image. Copy a copy of the service in the container content to realize concurrency from multiple services. The problem is that multiple service APIs are the same, but the port numbers are different, which involves how to provide only one port to the outside. Therefore, learn to use nginx for port forwarding.

The configured machine can be networked and has root permission. The overall process of Ubuntu system is relatively simple, but there are also some pits in the middle. However, it has been solved through the omnipotent Du Niang, which is hereby recorded.

Configure nginx:

1. Installation dependency

openssl   /   libssl-dev   /    gcc-c++

sudo apt-get install openssl
sudo apt-get install libssl-dev
sudo apt-get install gcc-c++
sudo apt-get gcc build-essential
sudo apt-get zlib
sudo apt-get zlib-devel

 2. Install PCRE

To download the installation package, enter the following from the command line:

cd /usr/local/src/
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

Unzip the installation package, enter the directory, compile and install, and view the pcre version

tar xzvf pcre-8.35.tar.gz
cd pcre-8.35
./configure                      #If there is an error in compilation, check whether the dependent installation is missing
make & make install        
pcre-config --version

3. Install nginx

To download the installation package, enter the following from the command line:

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

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.6.2.tar.gz

Unzip the installation package, enter the directory, compile and install, and start nginx

tar xzvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/src/nginx --with-http_ssl_module --with-http_stub_status_module                   #If there is an error in compilation, check whether the dependent installation is missing
make & make install        
get into/usr/local/src/nginx catalogue
./nginx #start nginx

 

Failed to start nginx!!!

[root@party-0]#find / -type f -name *libpcre.so.*  #View libpcre So file location

  

[root@party-0]#ln -s /lib/x86_64-linux-gnu/libpcre.so.3.13.2 /lib/x86_64-linux-gnu/libpcre.so.1   #Establish soft link

Restart again and you'll succeed.

Check whether nginx starts successfully

[root@party-0]#ps -ef | grep nginx

4. Configure nginx

cd /usr/local/src/nginx/conf    #Enter the configuration file directory
vim ngin.conf #Open profile

Find the position as shown in the figure and add the content in the red box.

First red box:

upstream searchsvr{             #searchsvr and proxy in the third red box_ Same name after pass
    server 10.80.33.139:8999;   #ip For local machine ip,The port is the service port, and the ports that need proxy are written here
    server 10.80.33.139:7766;
}

In the second red box, modify the port number to the only port provided outward. As mentioned above, 9000 ports are provided for customers, and two ports 8999 and 7766 are used for internal service of agents

Third red box:

location /hot{    #/api for hot services
    proxy_pass http://searchsvr;   #searchsvr corresponds to the name in the first red box
}

After configuration, restart nginx

cd /usr/local/src/ngin/sbin    #get into nginx catalogue
./nginx -s reload              #Restart nginx

Done!

 

Novices get on the bus. If the content is misleading due to errors, please leave a message for correction~

Reference website and other problem solving methods:

runoob. COM # NGINX installation and configuration tutorial: https://www.runoob.com/linux/nginx-install-setup.html

nginx installation: https://www.cnblogs.com/smfx1314/p/10546158.html

ubuntu uses yum command to report errors. Solutions: https://blog.csdn.net/liuchang__/article/details/78485568

./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such failed to start nginx: https://blog.csdn.net/weixin_44297303/article/details/89505398

nginx startup failed https://www.cnblogs.com/cnsanshao/p/3652510.html

                                        https://www.cnblogs.com/achengmu/p/9093814.html

                                        http://www.xwood.net/_site_domain_/_root/5870/5874/t_c278506.html

Error in installing OpenSSL dev: https://blog.csdn.net/liujian8654562/article/details/101113461