GCC G++ development class library

Before you start, please verify that the GCC g++ development library is installed. By default, the ububtu platform build environment can use the following command

apt-get install build-essential
apt-get install libtool
Copy the code

Centos platform compiler environment use the following command to install make:

yum -y install gcc automake autoconf libtool make
Copy the code

Install the g + + :

yum install gcc gcc-c++
Copy the code

Install the PCRE library

PCRE(Perl Compatible Regular Expressions) is a lightweight Perl function library, including the Perl-compatible Regular expression library. It’s much smaller than regular expression libraries like Boost. PCRE is easy to use and powerful enough to outperform the POSIX regular expression library and some classic regular expression libraries.

  1. Sourceforge.net/projects/pc PCRE is currently the latest version is 8.43, and it can… Download it here.

Wget not installed, need to install wGET first:

yum -y install wget
Copy the code
Wget HTTP: / / https://nchc.dl.sourceforge.net/project/pcre/pcre/8.43/pcre-8.43.tar.gzCopy the code
  1. useTar - ZXVF pcre 8.43. Tar. GzDecompress.
  2. runChmod -r 777 pcre - 8.43Grant full read and write permissions to the current folder.
  3. Switch to /pcre-8.43 and run./configureThe initial configuration of the PCRE will print a bunch of output information on the console.
  4. Execute the make operation to compile.
[root@server06 pcre-8.43]# make rm -f pcre_chartables.c ln -s./pcre_chartables.c ist pcre_chartables.c make all-am make[1]: Entering directory /opt/nginx/pcre-8.43 CC libpcre_la-pcre_byte_order.lo CC libpcre_la-pcre_compile.lo CC libpcre_la-pcre_config.lo CC libpcre_la-pcre_dfa_exec.lo CC libpcre_la-pcre_exec.lo CC libpcre_la-pcre_fullinfo.lo CC libpcre_la-pcre_get.lo CC libpcre_la-pcre_globals.lo CC libpcre_la-pcre_jit_compile.lo CC libpcre_la-pcre_maketables.lo CC libpcre_la-pcre_newline.lo CC libpcre_la-pcre_ord2utf8.lo CC libpcre_la-pcre_refcount.lo CC libpcre_la-pcre_string_utils.lo CC libpcre_la-pcre_study.lo CC libpcre_la-pcre_tables.lo CC libpcre_la-pcre_ucd.lo CC libpcre_la-pcre_valid_utf8.lo CC libpcre_la-pcre_version.lo CC libpcre_la-pcre_xclass.lo CC libpcre_la-pcre_chartables.lo CCLD libpcre.la CC libpcreposix_la-pcreposix.lo CCLD libpcreposix.la CXX libpcrecpp_la-pcrecpp.lo CXX libpcrecpp_la-pcre_scanner.lo CXX libpcrecpp_la-pcre_stringpiece.lo CXXLD libpcrecpp.la CC pcretest-pcretest.o CC pcretest-pcre_printint.o CCLD pcretest CC pcregrep-pcregrep.o CCLD pcregrep CXX pcrecpp_unittest-pcrecpp_unittest.o CXXLD pcrecpp_unittest CXX pcre_scanner_unittest-pcre_scanner_unittest.o CXXLD pcre_scanner_unittest CXX pcre_stringpiece_unittest-pcre_stringpiece_unittest.o CXXLD pcre_stringpiece_unittest make[1]: Brigade directory/opt/nginx/pcre - 8.43Copy the code
  1. Run [root@server06 pcre-8.43]# make install to install the pcRE.
[root @ server06 pcre 8.43] # make installCopy the code

Install the zlib library

Zlib.net/zlib-1.2.11… Zlib source package, use the following command to download and install zlib package: (in this paper, with reference to the download file version: zlib – 1.2.8. Tar. Gz after verification is not found this version, if you want to download the latest version, please open the above url. This article selects zlib-1.2.11.tar.gz)

CD /usr/local/src wget http://zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz CD zlib-1.2.11. /configure make make installCopy the code

4, Install OpenSSL (some VPS do not install SSL by default)

CD/usr/local/SRC wget https://www.openssl.org/source/openssl-1.0.2t.tar.gz tar - ZXVF openssl - 1.0.2 t.t ar. Gz CD Openssl-1.0.2t mkdir /usr/local/openssl. /config --prefix=/usr/local/openssl make make installCopy the code

Install nginx

There are two versions of Nginx, one is stable and the other is development. You can choose either version for your purposes. Here are the steps to install Nginx in /usr/local/nginx:

Go to the /usr/local directory

Wget http://nginx.org/download/nginx-1.20.1.tar.gz tar - ZXVF nginx - 1.20.1. Tar. Gz CD nginx - 1.20.1. / configure the make installCopy the code

Note: Errors may occur here

Ubuntu below:

apt-get install openssl
apt-get install libssl-dev
Copy the code

Under centos:

yum -y install openssl openssl-devel
Copy the code

Nginx common commands

(1) Start

Nginx installation directory address -c nginx configuration file address Example:

[root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Copy the code

(two), stop

Nginx can be stopped in three ways:

Easy to stop

1. View the process ID
[root@LinuxServer ~]# ps -ef|grep nginx
Copy the code

2. Kill the process
[root@LinuxServer ~]# kill -QUIT 2072
Copy the code

A quick stop

1. View the process ID
[root@LinuxServer ~]# ps -ef|grep nginx
Copy the code

2. Kill the process
[root@LinuxServer ~]# kill -term 2132 or [root@LinuxServer ~]# kill -int 2132Copy the code

Forced to stop

[root@LinuxServer ~]# pkill -9 nginx
Copy the code

(three), restart

1. Verify that the nginx configuration file is correct

Method 1: Go to the nginx installation directory sbin and run the./nginx -t command. The following information is displayed:

nginx.conf syntax is ok
nginx.conf test is successful
Copy the code

The configuration file is correct!

Method 2: Add -t before the -c command

2. Restart the Nginx service

Method 1: Go to the nginx executable directory sbin and run the./nginx -s reload command

Method 2: Search for the current Nginx process id and run the kill -hup process ID command to restart the nginx service

7. Configuration of environment variables

1: Access the vim /etc/profile fileCreate a PATH. (PATH is similar to configuring environment variables on Windows.) Export is used to import and enable the configuration.

3: configure the.bashrc file. At this point, you just need to do the following:

vim ~/.bashrc
Copy the code

And then the last line adds

source /etc/profile
Copy the code

/ nginx-s reload found no error

Then I started nginx again and said it was successful.

8. Configuration files

Nginx. conf configuration file:

worker_processes  auto;
events {
    worker_connections 102400;
    accept_mutex on;
    multi_accept on;
    use epoll;
}
http {
    log_format main '$remote_addr - $remote_user [$time_local] $request'
      '$status $body_bytes_sent $http_referer' 
      '$http_user_agent $http_x_forwarded_for';
    include  mime.types;
    keepalive_timeout  65;
	limit_req_zone $binary_remote_addr zone=one:200m rate=2000r/s;
    gzip on;
   #gzip_static on;
    gzip_min_length 1k;
    gzip_buffers  4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 6;
    gzip_types  text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
	gzip_proxied expired no-cache no-store private auth;
    server_tokens off;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    access_log /var/log/nginx/access.log main;
    error_log /var/log/nginx/error.log debug;
    client_header_timeout 10;
    client_body_timeout 10;
	client_max_body_size 200m;
    reset_timedout_connection on;
    send_timeout 10;
    limit_conn_zone $binary_remote_addr zone=addr:5m;
    limit_conn addr 100;
    default_type text/html;
    charset UTF-8;
    open_file_cache max=100000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;
    include vhosts/*.conf;
}
Copy the code

Configuration in vhosts:

server {
    listen 80;
    server_name 127.0. 01.;
    location / 
    {
        root   /home/www/jdz;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
		proxy_set_header X-Real-IP $remote_addr;
		limit_req zone=one burst=5000 nodelay;
    }
    location /api/ 
    {
        proxy_pass http:/ / 192.168.0.85:8301 /;
        proxy_redirect default;
		proxy_set_header X-Real-IP $remote_addr;
		limit_req zone=one burst=5000nodelay; }}Copy the code

HTTPS configuration:

server {
    listen 443 ssl;
    server_name sincerity-group.greatedu.net.cn;
    ssl_certificate /etc/ssl/4437701_sincerity-group.greatedu.net.cn.pem;
    ssl_certificate_key /etc/ssl/4437701_sincerity-group.greatedu.net.cn.key;
    ssl_protocols TLSv1 TLSv11. TLSv12.; ssl_session_timeout 10m; ssl_session_cache shared:SSL:10m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:! aNULL:! MD5:! RC4:! DHE; ssl_prefer_server_ciphers on; location / { root /home/www/pc_trustcms; index index.html index.htm; try_files $uri $uri/ /index.html; proxy_set_header X-Real-IP $remote_addr; limit_req zone=one burst=5000 nodelay;
    }

    location /api/
    {
        proxy_pass http:/ / 127.0.0.1:8888 /;
        proxy_redirect default;
		proxy_set_header X-Real-IP $remote_addr;
		limit_req zone=one burst=5000 nodelay;
    }
}

server {
    listen          80;
    server_name     www.js7e.com;
    rewrite ^(.*)$  https://$host$1 permanent;
}
Copy the code

Ix. Project packaging

Git clone http://192.168.0.205:8880/baosheng/jdzsoftware.git NPM install NPM start (in order to confirm whether the project can run normally) NPM run build: pro NPM  run upload:proCopy the code

10. Set nginx to start automatically after startup

Step 1: Go to the /lib/systemd/system/ directory

[root@iz2z init.d]# cd /lib/systemd/system/
Copy the code

Step 2: Create the nginx.service file and edit it

# vim nginx.service
Copy the code

As follows:

[Unit]
Description=nginx service
After=network.target 
   
[Service] 
Type=forking 
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true 
   
[Install] 
WantedBy=multi-user.target
Copy the code

Description: Describes the Service After: describes the Service category. [Service] Setting of Service running parameters. Type=forking Is the form of background running PrivateTmp=True: Independent temporary space is allocated to the Service. Note: The start, restart, and stop commands of [Service] all require the absolute path [Install]. The operating level of the Service can be set to multiple users, that is, the operating level is 3

Save and exit.

Step 3: Add boot autostart

systemctl enable nginx
Copy the code

If you do not want the startup to start, you can use the following command to cancel the startup

# systemctl disable nginx
Copy the code

Step 4: Start/stop the service/refresh the configuration file/view the status

#Systemctl start nginx.service Starts the nginx service

#Systemctl stop nginx.service Stops the service

#Systemctl restart nginx.service Restarts the service

# systemctl list-units --type=service Displays all started services

#Systemctl status nginx.service Views the current service status

# systemctl enableNginx. service sets automatic startup upon startup

# systemctl disableNginx. service Stops startup
Copy the code

11. Frequently Asked Questions

Nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)?

If the port number is occupied, go to /usr/local/nginx/conf/ and change the port number in nginx.conf. If nginx restarts several times, close the nginx process and restart it.

Closed Nginx use ps – ef | grep Nginx view Nginx process, you can see Nginx has two processes:

[root@linuxidc sbin]# ps -ef|grep nginx 
root      7276    1  0 14:21 ?        00:00:00 nginx: master process ./nginx
www      7277  7276  0 14:21 ?        00:00:00 nginx: worker process
root      7279  5197  0 14:21 pts/1    00:00:00 grep nginx
Copy the code

Quick stop nginx kill -quit Indicates the main nginx process ID

Stop all nginx processes

[root@linuxidc sbin]# pkill -9 nginx
Copy the code

2. Failed to initialize./configure

Run./configure to initialize the configuration. If the following information is displayed, the PCRE is not installed on the machine. Nginx relies on PCRE and needs to install PCRE manually

After installing PCRE, run./configure again to initialize it. Note that the generated configuration file, especially the direction of the arrow, is the path to start Nginx

3 after the restart, kill process, appear ginx: [error] invalid PID number “” in”/usr/local/nginx/logs/nginx PID “this mistake

Use the/usr/local/nginx/sbin/nginx -s reload again error reading configuration file:

[root@localhost nginx]/usr/local/nginx/sbin/nginx -s reload
Copy the code

Tip:

nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
[root@localhost nginx]# cd logs
[root@localhost logs]# ls
access.log  error.log  nginx-access.log  nginx_error.log
Copy the code

Indeed no/usr/local/nginx/logs/nginx pid file

Solutions:

[root@localhost nginx]/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Copy the code

Install GCC and gcc-C ++

Package download address: test available

Link: pan.baidu.com/s/1j5-yzDbp… Password: teta

Upload centos to the Linux server and go to the centos directory

perform

rpm -Uvh *.rpm --nodeps --force
Copy the code

Install GCC and gcc-C ++. Install GCC and gcc-C ++ in offline environment.

gcc -v
g++ -v
Copy the code