Nginx configuration (windows and Linux)

Time:2021-7-30

Windows Edition

Baidu download nginx / windosw and unzip it

Nginx command:
Start command start nginx
Restart command nginx – s reload
Stop command nginx – s stop

Profile configuration

#Image server proxy image.jt.com: 80
    server {
        listen 80;
        server_name image.jt.com;

        location / {
            #Turn to directory
            root D:/JT-SOFT/images;
        }
    }

Listen indicates the listening port, server_ Name indicates the listening address

If you want to access locally, you need to modify the hosts file

#Jingtao configuration  
#Write the IP address on the left and the domain name on the right, separated by a space
127.0.0.1   image.jt.com
127.0.0.1   manage.jt.com

#Implementation of nginx
#192.168.126.129   image.jt.com
#192.168.126.129   manage.jt.com
127.0.0.1   www.jt.com
#Bug sometimes loses letters when using the software
127.0.0.1   sso.jt.com

Nginx deploys the tomocat cluster, and the project issues the command Java – jar

#Configure Jingtao background management server
    #Manage.jt.com localhost: 8091 server
    server {
        listen 80;
        server_name manage.jt.com;

        location / {

            #Mapping server
            proxy_pass  http://localhost:8091;
        }
    }

Nginx for load balancing

#Configure Jingtao background management server
    #Manage.jt.com localhost: 8091 server
    server {
        listen 80;
        server_name manage.jt.com;

        location / {

            #Mapping server
            #proxy_pass  http://localhost:8091;
            proxy_pass   http://jtWindows;    
        }
    }

    #Configure Tomcat server cluster 1. Polling policy
    upstream jtWindows {

        #Server represents the server address
        server 127.0.0.1:8081;
        server 127.0.0.1:8082;    
    }

Weight setting allows servers with better performance to process multiple requests

#Configure Tomcat server cluster 1. Polling policy 2. Weight policy
    upstream jtWindows {

        #Server represents the server address
        server 127.0.0.1:8081 weight=8;
        server 127.0.0.1:8082 weight=2;    
    }

Iphash policy: since some data is bound to the server, the iphash policy is used when the user must access the specified server later

#Configure Tomcat server cluster 1. Polling policy 2. Weight policy 3. Iphash policy
    upstream jtWindows {

        #Server represents the server address
        ip_hash;
        server 127.0.0.1:8081 weight=8;
        server 127.0.0.1:8082 weight=2;    
    }

Linux version

To install JDK, first upload the JDK file for Linux and unzip it
Command: tar -zxvf jdk-8u51-linux-x64.tar.gz
Configure environment variables

Set JDK environment

#Set JDK environment
export JAVA_HOME=/usr/local/src/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib

Installing the MariaDB database

Test whether you can connect to the Internet – ping

Installation command:
[ [email protected] Src]# install MariaDB database using Yum install MariaDB server
[ [email protected] Src]# Yum clean all empties the installed files. If the download fails, execute

OK to download: press y

Database startup command:

1. Start command[ [email protected]  src]# systemctl  start  mariadb
2. Restart command[ [email protected]  src]# systemctl  restart  mariadb
3. Close command[ [email protected]  src]# systemctl  stop  mariadb

Database initialization operation:
Command: MySQL_ secure_ installation
Then press y

Test whether the user name and password are valid, MySQL – uroot – proot
Import database: source / XX / XX / XX / jtdb.sql;

Description of linked database:

  1. If you need to remotely link the database, you must pass through the firewall
  2. If the database is linked remotely, the remote access permission must be enabled in the database, otherwise the link is rejected

Configure database permissions
1. Enter the database: MySQL – uroot – proot
2. Use database: use MySQL
3. Query the host / root / password in the user table:
select host,user,password from user
4. Change host = “localhost” to “%”:
update user set host=”%” where host=”localhost”;
5. Refresh database permissions
flush privileges

Configure Linux Firewall
Command: firewall CMD — state / / view status
Systemctl enable firewalld.service / / set startup and enable firewall
Systemctl disable firewalld. Service / / set startup and disable firewall
Systemctl stop firewalld. Service / / manually turn off the firewall
Systemctl start firewalld. Service / / turn on the firewall
Firewall CMD — List ports / / check the open ports of the firewall
Firewall CMD — Query port 80 / TCP check whether port 80 is open
firewall-cmd –zone=public –add-port=80/tcp –permanent
//Open port 80
Firewall CMD — zone = public — remove port = 9090 / TCP – permanent / / remove port 9090
Firewall CMD — reload / / restart the firewall
Firewall operation explanation
– zone # scope
– add port = 80 / TCP # add port in the format of port / communication protocol
– remove port = 80 / TCP # removes the port in the format of port / communication protocol
– permanent # takes effect permanently. If there is no such parameter, it will become invalid after restart

Command: JPS retrieve java process

  1. Kill PID number “humble kill process” if the current process item is used by other processes, it will not be closed
  2. Kill – 15 PID “gentle kill” can be dealt with before being killed
  3. Kill – 9 PID forced kill

Retrieve any process
PS – ef| grep XXXX server name

Linux deployment nginx

1. Baidu downloads nginx Linux
2. Upload to the server and decompress
tar -zxvf nginx-1.19.3.tar.gz
3. Enter the nignx directory for installation,
Command:. / configure

  make
  make install

4. After installation, enter the directory, which is / usr / local / nginx by default
Enter the SBIN directory with the command:. / nginx
Command description:
. / nginx start nginx
. / nginx – s reload restart nginx
./nginx -s stop
5. Restart nginx after modifying the configuration file

#1. Configure Linux Cluster
    server {
        listen 80;
        server_name manage.jt.com;

        location / {
            proxy_pass http://tomcats;
        }
    }

    upstream tomcats {
        server  192.168.126.129:8081;
        server  192.168.126.129:8082;
    }
    

    #Configure Linux picture agent
    server {
        listen 80;
        server_name  image.jt.com;

        location / {
            #Configure picture disk address
            root  /usr/local/src/images;
        }
    }

Recommended Today

Programming Xiaobai must understand the network principle

How is the network composed? Why can we easily surf the Internet now?Whether you are a computer major or not, you may always have such questions in your heart!And today we will solve this matter and tell you the real answer! Basic composition of network First, let’s look at this sentence Connect all computers together […]