nginx installs and configures port forwarding

1. Upload the nginx package to the server. I use nginx-1.21.6.tar.gz here
2. Unzip nginx

tar -zxvf nginx-1.21.6.tar.gz

3. After decompression, a nginx-1.21.6 directory will be generated in the current directory
4. Enter the directory and execute --with stream

./configure --prefix=Installation path --with-stream ? ? The part marked in red is mandatory, and it is not supported if it is not added tcp forward

5. The following errors may appear after running the command, which means that there are no pcre, pcre devel and zlib devel packages on your server. Install them with the yum command

??? ?yum -y install pcre

??? ?yum -y install pcre-devel

??? ?yum -y install zlib-devel

6. Execute the command in step 4 again

7. Execute the command to install

make && make install

8. Here, nginx has been installed. Next, configure the nginx.conf file

Configuration file path: / your installation path /nginx/conf/nginx.conf

9. Edit the configuration file as nginx Conf default content, please back up this file before modifying

cp nginx.conf nginx_bak.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/;

events {
    wor{er_connections  1024;

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
"nginx.conf" 117L, 2656C                                                                             1,0-1        é????
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;

        #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;

        # proxy the PHP scripts to Apache listening on
        #location ~ .php$ {
        #    proxy_pass;

        # pass the PHP scripts to FastCGI server listening on
        #location ~ .php$ {
        #    root           html;
        #    fastcgi_pass;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #location ~ /.ht {
        #    deny  all;

    # another virtual host using mix of IP-, name-, and port-based configuration
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }

    # HTTPS server
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }


10. Add the following contents to the configuration file

stream {     --stream Part and http Partial level
   #These two sections realize that port is forwarded through port 22222 of the local server
   #The following two mysqltest s can be named by themselves, but they should be the same
   upstream mysqltest {
   server {
   listen 22222;
   proxy_pass mysqltest;

11. Nginx after adding content The details of conf are as follows, of which the red box is the new content. I have added two ports here. If you need to forward more ports, you can continue to add them in stream for port forwarding (the content of this configuration file only supports port forwarding function)

12. Start nginx

cd /home/collect/nginx/sbin
./nginx -c /home/collect/nginx/conf/nginx.conf

So far, the port forwarding has been completed and can be used

First of all, I would like to introduce myself. I graduated from Jiaotong University in 13 years. I once worked in a small company, went to large factories such as Huawei OPPO, and joined Alibaba in 18 years, until now. I know that most junior and intermediate Java engineers who want to improve their skills often need to explore and grow by themselves or sign up for classes, but there is a lot of pressure on training institutions to pay nearly 10000 yuan in tuition fees. The self-study efficiency of their own fragmentation is very low and long, and it is easy to encounter the ceiling technology to stop. Therefore, I collected a "full set of learning materials for java development" and gave it to you. The original intention is also very simple. I hope to help friends who want to learn by themselves and don't know where to start, and reduce everyone's burden at the same time. Add the business card below to get a full set of learning materials

Tags: Back-end Front-end Android Interview

Posted by dsoukup on Tue, 02 Aug 2022 03:01:01 +0930