Home >Operation and Maintenance >Nginx >Nginx brief installation and configuration example analysis
1. Files required for nginx installation
1), nginx-1.2.8.tar.gz
2), openssl-1.0.1g.tar .gz
3), pcre-8.31.tar.gz
4), zlib-1.2.7.tar.gz
The download addresses of the above installation packages are available normally. , since I am using the installation package of the above version, the following installations are based on this.
2. Linux machine configuration environment
2.1.java environment
$java -version java version "1.8.0_45" java(tm) se runtime environment (build 1.8.0_45-b14) java hotspot(tm) 64-bit server vm (build 25.45-b02, mixed mode)
2.2.Hardware configuration
3. Installation steps
3.1. Unzip the installation package
Enter the nginx installation directory and unzip openssl-1.0.1g.tar.gz and pcre respectively -8.31.tar.gz, zlib-1.2.7.tar.gz, nginx-1.2.8.tar.gz four tar packages, execute the command tar -zxvf xxxx.tar.gz, where xxxx is the package name.
After decompression:
3.2. Compile the installation package
First compile the 3 required Library file packages: openssl-1.0.1g, pcre-8.31, zlib-1.2.7.
Compile openssl-1.0.1g, enter the file directory, and execute the following commands in sequence:
$./config$make$make install
Normal installation result:
Compile pcre-8.31, enter the file directory, and execute the following commands in sequence:
$./config $make $make install
Normal installation result:
Compile zlib-1.2.7, enter the file directory, and execute the following commands in sequence:
$./configure $make $make install
Normal installation results:
Next, Compile the nginx installation package, enter the file directory, and execute ./configure. You need to specify the installation directory –prefix=/opt/nginx/nginx and the path of the corresponding library file
sudo ./configure --prefix=/opt/nginx /nginx --with-openssl=/opt/nginx/openssl-1.0.1g --with-pcre=/opt/nginx/pcre-8.31 --with-zlib=/opt/nginx/zlib-1.2.7
Next, compile and install.
Copy code The code is as follows:
sudo ./configure --prefix=/opt/nginx/nginx --with-openssl=/opt/nginx/openssl-1.0.1g --with -pcre=/opt/nginx/pcre-8.31 --with-zlib=/opt/nginx/zlib-1.2.7
Next, compile and install.
$make
$make install
At this point, the nginx installation is completed.
3.3. Start nginx
Enter the nginx installation directory/opt/nginx/nginx/sbin and execute ./nginx to start the service.
[dddd.et15sqa /opt/nginx/nginx/sbin]
$sudo ./nginx
View the service process after startup:
$ps aux|grep nginx
root 2295 0.0 0.0 28264 804 ? ss 23:30 0:00 nginx: master process ./nginx
nobody 2296 0.0 0.0 28660 1356 ? s 23:30 0:00 nginx: worker process
125233 2411 0.0 0.0 113720 1012 pts/0 s 23:31 0:00 grep nginx
Open nginx default homepage:
#Service installation and startup OK!
4. Port forwarding
You need to forward port 80 to the tomcat homepage running in the server, and its port is 8080.
tomcat home page:
## Configure the nginx.conf file of nginx as follows:server { listen 80; server_name 127.0.0.1; #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; #index index.html index.htm; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $remote_addr; proxy_pass http://127.0.0.1:8080; }Restart the nginx service, ./nginx -s reloadAt this time, you can access port 80, but it actually jumps to the service of port 8080.
The above is the detailed content of Nginx brief installation and configuration example analysis. For more information, please follow other related articles on the PHP Chinese website!