1. Install nginx ①. To make sure that you can use regular expressions for more flexible configuration in nginx, You need to determine whether the system has installed the PCRE (PerlCompatibleRegularExpressions) package before installation. You can download the latest PCRE source package from ftp: ftp. csx. cam. ac. ukpubsoftwareprogrammingpcre
1. Install nginx
(1) to ensure that it can be used in nginxRegular ExpressionExpressions for more flexible configuration. Before installation, determine whether the system has a PCRE (Perl Compatible Regular Expressions) package. You canFtp: // Ftp. csx. cam. ac. uk/pub/software/programming/pcre/download the latest PCRE source package, use the followingCommandDownload and compile the PCRE package:
# Wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.bz2
# Tar jxvf pcre-8.12.tar.bz2
#CdPcre-8.10
#./Configure?Enable-Utf8
# Make
# Make install
② Create users and user groups for nginx
# UseraDdWww-nginx
# Groupadd www skip some steps if the www user group already exists
# GPasswd-A www-nginx www
③ Install nginx
# Wget http://nginx.org/download/nginx-1.0.3.tar.gz
# Tar zxvf nginx-1.0.3.tar.gz
# Cd nginx-1.0.3
#./Configure
? Prefix =/usr
? Sbin-path =/usr/sbin/nginx
? Conf-path =/etc/nginx. conf
? Error-log-path =/var/log/nginx/error. log
? PId-Path =/var/run/nginx. pid
? Lock-path =/var/lock/nginx. lock
? User = www-nginx
? Group = www
? With-http_ssl_moDuLe
? With-http_stub _StatUs_module
? With-http_flv_module
? With-http_gZip_ Static_module
? Http-log-path =/var/log/nginx/access. log
? Http-client-body-temp-path =/var/tmp/nginx/client/
? Http-proxy-temp-path =/var/tmp/nginx/proxy/
? Http-fastcgi-temp-path =/var/tmp/nginx/fcgi/
// Simple installation./configure? User = www-nginx? Group = www? Prefix =/opt/nginx? With-http_stub_status_module? With-http_ssl_module
# Make
# Make install
? The with-http_stub_status_module is used to enable nginx's NginxStatus function to monitor the current state of nginx.
? With-http_ssl_module enables the http_ssl Module
? With-ipv6 supports ipv6
After the installation is successful, the/opt/nginx directory contains four subdirectories: conf, html, logs, and sbin. The nginx configuration file is stored in conf/nginx. conf. nginx only has one program file in the nginx file under the sbin directory. Make sure that port 80 of the system is not occupied by other programs. Run the sbin/nginx command to start Nginx and open the browser to access the IP address of the machine. If the browser displays Welcome to nginx! Nginx has been installed and runs successfully.
2. Use OpenSSL to generate a certificate
Create and enter the sslkey storage directory
#Mkdir/Opt/nginx/sslkey
# Cd/opt/nginx/sslkey
① Generate an RSA key:
# Openssl genrsa-out key. pem 2048
② Generate a certificate request
# Openssl req-new-key. pem-out cert. csr
# // The system will prompt you to enter the province, city, domain name information, etc. What's important is that email must be your domain name suffix. You can take this file to the Digital Certificate Authority (CA) apply for a digital certificate. CA will give you a new file cacert. pem, which is your digital certificate.
If you do the test on your own, you can use the following command to generate the certificate:
# Openssl req-new-x509-nodes-out server. crt-keyout server. key
③ Modify nginx Configuration
UpsTrEam payment {
Server 127.0.0.1: 8080;
Server 127.0.0.1: 8090;
}
# HTTPS server
#
Server {
Listen 443;
Server_name www.openeasy.net;
Ssl on;
Ssl_certifiCatE/opt/nginx/sslkey/server. crt;
Ssl_certificate_key/opt/nginx/sslkey/server. key;
Ssl_session _TimeOut 5 m;
Ssl_protocoLsSSLv2 SSLv3 TLSv1;
Ssl_ciphers ALL :! ADH :! EXPORT56: RC4 + RSA: + HIGH: + MEDIUM: + LOW: + SSLv2: + EXP;
Ssl_prefer_server_ciphers on;
Location /{
Proxy_pass http: // payment /;
Proxy_rEdIrect off;
Proxy _Set_ Header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_connect_timeout 10 s;
Proxy_read_timeout 10 s;
}
}
3. Configure jExUs linux dotnet ServerCluster
Upstream payment {
Server 127.0.0.1: 8080;
Server 127.0.0.1: 8090;
}
Here, the server is your Jexus server LIST. For details about the configuration, see use Jexus V4.2 to build a Linux dotnet web server.
Common Nginx parameters and Control
Program running parameters
After Nginx is installed, there is only one program file, which does not provide various management programs. It uses parameters and system signal mechanisms to control the Nginx process itself. Nginx parameters include the following:
-C: Use the specified configuration file instead of nginx. conf In the conf directory.
-T: test whether the configuration file is correct. This command is very important when you need to re-load the configuration file during running. It is used to detect whether the modified configuration file has syntax errors.
-V: displays the nginx version number.
-V: displays the nginx version number, compilation environment information, and compilation parameters.
For example, to test whether a configuration file is correctly written, run the following command:
Sbin/nginx? T? C conf/nginx2.conf
Control nginx by Signal
Nginx supports the following signals:
Description
The TERM and INT are used to quickly close the program and stop the request being processed.
After QUIT finishes processing the current request, close the program
HUP reloads the configuration, starts a new working process, and closes the process. This operation will not interrupt the request.
USR1 re-opens the log file to switch logs. For example, a new log file is generated every day.
USR2 smooth upgrade executable program
WINCH calmly closes the Working Process
There are two ways to control Nginx through these signals. The first is to view the ID of the currently running nginx process through Nginx. pid in the logs directory.Kill? XXX to control Nginx, where XXX is the signal name listed in the above table. If your system has only one Nginx process, you can also run the killall command, for example, run killall? S HUP nginx to let Nginx reload the configuration.