First, the environment
Installation package: http://nginx.org/en/download.html
Service Firewalld Stop
Systemctl Disable FIREWALLD
Uploading an installation package to a virtual machine via WINSCP
Second, Nginx installation
Yum-y install \
GCC \
gcc-c++ \
Make \
Pcre-devel \
Zlib-devel
[[email protected] ~]# useradd-m-s/sbin/nologin nginx//Create program user Nginx, can't login, no home directory
[Email protected] ~]# tar xzvf nginx-1.13.9.tar.gz
[Email protected] ~]# CD nginx-1.13.9
[Email protected] nginx-1.13.9]#/configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module//Log Analysis module
[[email protected] nginx-1.13.9]# make && make install//compile and install
[[email protected] nginx-1.13.9]# ln-s/usr/local/nginx/sbin/nginx/usr/local/sbin///For the Nginx executable to do soft connection, so that the system can recognize
NGINX-T//config file Syntax check
Nginx//Start-up service
KILLALL-1 nginx//safe restart
Killall-3 nginx//Stop service
----------------------------------------production Management corner of the---------------------------
[Email protected] nginx-1.13.9]# Vi/etc/init.d/nginx
#!/bin/bash
CHKCONFIG:35 99 20//3,5 level Autorun, 99th process open, 20th process end Description:nginx Service Control Script
Prog= "/usr/local/nginx/sbin/nginx"
pidf= "/usr/local/nginx/logs/nginx.pid"
Case "$" in
Start
$PROG
;;
Stop
Kill-s QUIT $ (cat $PIDF)
;;
Restart
$ stop
$ start
;;
Reload
Kill-s HUP $ (cat $PIDF)
;;
*)
echo "Usage: $ {start|stop|restart|reload}"
Exit 1
Esac
Exit 0
: X
[[email protected] nginx-1.13.9]# chmod +x/etc/init.d/nginx//Add Execute permissions to administrative scripts
[[email protected] nginx-1.13.9]# chkconfig--add nginx//Add Nginx to chkconfig system Administration tool
------------------------the initial configuration of the Nginx configuration file-------------------
[Email protected] nginx-1.13.9]# vi/usr/local/nginx/conf/nginx.conf
User Nginx Nginx; Modify the owner and group of the Nginx boot process
Worker_processes 1; CPU cores, several cores are set to a few
Error_log Logs/error.log Info; To modify the level of the error log
Note: The log level is common to these types: Debug Info notice warn error crit where the rules are logged up, that is, the info level log will cover notice warn error crit, lower level of inclusion advanced, not in the config file
Events {
use Epoll;//Add this line by default using Select/poll
Worker_connections 1024;//= 1 processes allow 1024 connections, If you set more than 1024, you need to modify the Ulimit cap or error (ulimit-n 65500//View and change the number of local open resources on the system
Ulimit-n 65500 >>/etc/rc.local)
Log_ Format Main//define log formats to remove the previous # number after the
[[email protected] nginx-1.13.9]# service nginx Restart
is configured to restart, Now the Nginx server has been able to support access to the
------------------------------------ Configure the log statistics module that comes with Nginx------------------------------------
[[email protected] nginx-1.13.9]# vi/usr/local/ nginx/conf/nginx.conf
Location ~/status {
Stub_status on;
Access_log off;
}
[[email protected] nginx-1.13.9]# service nginx Reload
[[email protected] nginx-1.13.9]# CAT/ Usr/local/nginx/logs/access.log
Browser: http://IP/status//Current number of active connections, number of connections processed, number of successful TCP handshakes, requests processed.
------------------------The following configuration of the Nginx authentication function----------------------------
[[email protected] nginx-1.13.9]# Yum install httpd-tools-y//Installing Apache tools to create access users with tools
[[email protected] nginx-1.13.9]# htpasswd-c/usr/local/nginx/passwd.db Jack//Create a database validation file and add the jack user in
New Password: Lost password
Re-type New password: Confirm password
Adding Password for user jack
[[email protected] nginx-1.13.9]# chmod 400/usr/local/nginx/passwd.db//Improve data security
[Email protected] nginx-1.13.9]# chown nginx/usr/local/nginx/passwd.db//change owner
[Email protected] nginx-1.13.9]# vi/usr/local/nginx/conf/nginx.conf
Location/{
root HTML;
Index index.html index.htm;
Allow 192.168.80.0/24;
Deny all;
Auth_basic "Secret";
auth_basic_user_file/usr/local/nginx/passwd.db; Note that this file must be consistent with the database validation file created above
}
[[Email protected] nginx-1.13.9]# service Nginx restart
Re-access requires user name and password
Three, the following configure the virtual host function
-----------Domain-based----------IP and port are the same but the domain name is not the same----------
[Email protected] nginx-1.13.9]# vi/usr/local/nginx/conf/nginx.conf
"Insert on last line, last line is a}, end total 4}"
server {
Listen 80;
server_name www.aa.com;
CharSet Utf-8;
Access_log Logs/aa.access.log Main;
Location/{
root/usr/local/nginx/html;
Index index.html index.htm;
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}
}
server {
Listen 80;
server_name www.bc.com;
CharSet Utf-8;
Access_log Logs/bc.access.log Main;
Location/{
ROOT/VAR/WWW/BC;
Index index.html index.htm;
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}
}
Remove the comment below
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"‘;
[Email protected] nginx-1.13.9]# mkdir/var/www/aa-p
[Email protected] nginx-1.13.9]# MKDIR/VAR/WWW/BC
Add a home page to a site Directory of two virtual hosts
[Email protected] nginx-1.13.9]# vi/var/www/aa/index.html
[Email protected] nginx-1.13.9]# vi/var/www/bc/index.html
Modify the Microsoft Hosts file for virtual host testing:
The Windows XP/2003/VISTA/2008/7/8 user Hosts file is in the "c:\windows\system32\drivers\etc
The Hosts file adds this sentence: 192.168.80.102 www.aa.com www.bc.com
[Email protected] nginx-1.13.9]# nginx–t
[[Email protected] nginx-1.13.9]# service Nginx restart
[Email protected] nginx-1.13.9]# killall-1 Nginx
Iv. installation of MySQL
[Email protected] ~]# yum-y install ncurses ncurses-devel Bison cmake
[[email protected] ~]# useradd-s/sbin/nologin mysql//manually build an account
[[Email protected] ~]# tar XF mysql-boost-5.7.20.tar.gz-c/opt///Unzip the directory to be large enough, or will error
[Email protected] mysql-5.7.20]# cd/opt/mysql-5.7.20/
CMake \
-dcmake_install_prefix=/usr/local/mysql \
-dmysql_unix_addr=/usr/local/mysql/mysql.sock \//Specify the path of the sock file
-DSYSCONFDIR=/ETC \
-dsystemd_pid_dir=/usr/local/mysql \
-ddefault_charset=utf8 \
-DDEFAULT_COLLATION=UTF8_GENERAL_CI \
-dwith_innobase_storage_engine=1 \
-dwith_archive_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-dwith_perfschema_storage_engine=1 \
-dmysql_datadir=/usr/local/mysql/data \//Data folder
-dwith_boost=boost \
-dwith_systemd=1
[[email protected] mysql-5.7.20]# make && make install
[Email protected] mysql-5.7.20]# chown-r mysql:mysql/usr/local/mysql/
[Email protected] mysql-5.7.20]# VI/ETC/MY.CNF
[Client]
Port = 3306
Default-character-set=utf8
Socket =/usr/local/mysql/mysql.sock
[MySQL]
Port = 3306
Default-character-set=utf8
Socket =/usr/local/mysql/mysql.sock
[Mysqld]
user = MySQL
Basedir =/usr/local/mysql
DataDir =/usr/local/mysql/data
Port = 3306
Character_set_server=utf8
Pid-file =/usr/local/mysql/mysqld.pid
Socket =/usr/local/mysql/mysql.sock
Server-id = 1
Sql_mode=no_engine_substitution,strict_trans_tables,no_auto_create_user,no_auto_value_on_zero,no_zero_in_date, No_zero_date,error_for_division_by_zero,pipes_as_concat,ansi_quotes//fixed format
: X
[Email protected] mysql-5.7.20]# chown mysql:mysql/etc/my.cnf
[Email protected] mysql-5.7.20]# echo ' path=/usr/local/mysql/bin:/usr/local/mysql/lib: $PATH ' >>/etc/profile/ /Add these two paths to the environment variable and put them in the profile file to start from running, otherwise it won't take effect
[[email protected] mysql-5.7.20]# echo ' export PATH ' >>/etc/profile//can also be soft link
[[email protected] mysql-5.7.20]# source/etc/profile//immediate effect
[Email protected] mysql-5.7.20]# cd/usr/local/mysql/
BIN/MYSQLD \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data//mysql Initialization
[email protected] mysql]# CP usr/lib/systemd/system/mysqld.service/usr/lib/systemd/system/
[Email protected] mysql]# Systemctl daemon-reload
[Email protected] mysql]# systemctl start mysqld
[Email protected] mysql]# NETSTAT-ANPT | grep 3306
[Email protected] mysql]# Systemctl enable mysqld
[Email protected] mysql]# mysqladmin-u root-p password "123"
Enter Password: (The initial password is empty, the direct return is good)
[Email protected] mysql]# mysql-u root–p
Mysql>
Mysql>
Mysql> quit
Bye
V. Installation of PHP
[[email protected] mysql]# yum-y install \
Libjpeg \
Libjpeg-devel \
Libpng libpng-devel \
FreeType freetype-devel \
LIBXML2 \
Libxml2-devel \
Zlib zlib-devel \
Curl curl-devel \
OpenSSL openssl-devel//Install the plug-in needed to support
[Email protected] ~]# yum-y install bzip2
[Email protected] ~]# tar xjvf php-7.1.10.tar.bz2-c/opt/
[Email protected] ~]# cd/opt/php-7.1.10
[Email protected] php-7.1.10]#/configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--WITH-MYSQLI \
--with-zlib \
--with-curl \
--WITH-GD \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--WITH-OPENSSL \//Configure collaboration
--enable-mbstring \
--enable-xml \
--enable-session \
--ENABLE-FTP \
--ENABLE-PDO \
--enable-tokenizer \
--enable-zip \//Support compression
--ENABLE-FPM//Support Dynamic page FPM function (Note this to hand, direct copy easy failure)
[[email protected] php-7.1.10]# make && make install
[[email protected] php-7.1.10]# CP php.ini-development/usr/local/php/lib/php.ini//Copy PHP profile template as php config file
[[email protected] php-7.1.10]# Vi/usr/local/php/lib/php.ini//Edit PHP config file
Mysqli.default_socket =/usr/local/mysql/mysql.sock//Edit the sock file location for MySQL
Date.timezone = Asia/shanghai//select time zone
[[email protected] php-7.1.10]#/usr/local/php/bin/php–m//Verify the installed module
-----------Configuring and optimizing the FPM module--------
[Email protected] php-7.1.10]# cd/usr/local/php/etc/
[[email protected] etc]# CP php-fpm.conf.default php-fpm.conf//Copy PHP fpm Module profile template for configuration file. PHP only recognizes php-fpm.conf as a configuration file
[Email protected] etc]# cd/usr/local/php/etc/php-fpm.d/
[[email protected] php-fpm.d]# CP www.conf.default www.conf//copy fpm www profile template as config file, FPM only recognizes www.conf configuration file
[Email protected] php-fpm.d]# cd/usr/local/php/etc/
[[Email protected] etc]# VI php-fpm.conf//configure FPM Module
PID = run/php-fpm.pid//semicolon is removed
; user = Nginx
; group = nginx//Add user and Group
[[email protected] etc]#/usr/local/php/sbin/php-fpm-c/usr/local/php/etc/php.ini//Start FPM module
[Email protected] etc]# NETSTAT-ANPT | grep 9000
[[email protected] etc]# ln-s/usr/local/php/bin/*/usr/local/bin///Put PHP's executable program into a system-aware environment for easy execution
[[Email protected] etc]# PS aux | Grep-c "PHP-FPM"//number of statistical processes
-----Update the startup script to enable the FPM module to start management----------
[Email protected] etc]# Vi/etc/init.d/nginx
#!/bin/bash
chkconfig:35 20description:nginx Service Control Script
Prog= "/usr/local/nginx/sbin/nginx"
pidf= "/usr/local/nginx/logs/nginx.pid"
Prog_fpm= "/USR/LOCAL/PHP/SBIN/PHP-FPM"
Pidf_fpm= "/usr/local/php/var/run/php-fpm.pid"
Case "$" in
Start
$PROG
$PROG _FPM
;;
Stop
Kill-s QUIT $ (cat $PIDF)
Kill-s QUIT $ (cat $PIDF _fpm)
;;
Restart
$ stop
$ start
;;
Reload
Kill-s HUP $ (cat $PIDF)
;;
)
Echo "Usage: $ {start|stop|restart|reload}"
Exit 1
Esac
Exit 0
------------------- The following is a PHP feature for nginx support--------------
[[email protected] etc]# vi/usr/local/nginx/conf/nginx.conf
Location ~. php$ {
root/usr/local/nginx/html;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param script_filename/usr/local/nginx/html$fastcgi_script_name;//Note the directory name, which must be an absolute path for the site root
include Fastcgi_params;
}
[[[email protected] etc]# vi/usr/local/nginx/html/index.php
<?php
Phpinfo ();
?
[[email protected] etc]# nginx-t
[[email protected] etc]# service nginx Restart
Note that, in order to prevent interference, You need to remove the virtual host Configuration
in Web page test http://192.168.80.193/index.php
----------------------------------- The following test database is working correctly---------------------
[[email protected] etc]# mysql-u root-p
Enter password: password
MySQL > CREATE DATABASE bbs; Create the database for BBS
mysql> GRANT all on BBS. To ' bbsadm ' @ '% ' of ' identified by ' admin123 '; Give the database all permissions to bbsadm with the password admin123
Mysql> GRANT all on bbs.* to ' bbsadm ' @ ' localhost ' identified by ' admin123 '; Allow
mysql> flush Privileges; Refresh Permissions
Mysql> quit
[Email protected] etc]# vi/usr/local/nginx/html/index.php
<?php
$link =mysqli_connect (' 192.168.80.102 ', ' bbsadm ', ' admin123 ');
if ($link) echo "else echo "fail!!";
?>
Test "http://IP/index.php" on the Web page
---------------------The following installation forums---------------------------
[email protected] etc]# Yum install-y unzip
[Email protected] etc]# unzip discuz_x3.4_sc_utf8_0101.zip-d/opt//Unzip
[[email protected] ~]# cd/opt/dir_sc_utf8///go to unzip directory
[Email protected] dir_sc_utf8]# cp-r upload//usr/local/nginx/html/bbs
[Email protected] dir_sc_utf8]# Cd/usr/local/nginx/html/bbs
[Email protected] bbs]# chown-r Root:nginx./config/
[Email protected] bbs]# chown-r Root:nginx./data/
[Email protected] bbs]# chown-r Root:nginx./uc_client/
[Email protected] bbs]# chown-r Root:nginx./uc_server/
[Email protected] bbs]#
[Email protected] bbs]# chmod-r 777./config/
[Email protected] bbs]# chmod-r 777./data/
[Email protected] bbs]# chmod-r 777./uc_client/
[Email protected] bbs]# chmod-r 777./uc_server/
Visit http://IP/bbs/install/index.php//Installation Forum
Access address is http://IP/bbs/index.php
http://IP/bbs/admin.php//Management background
-------------------------------------configuration of static and dynamic separation---------------------------
Remove access Control
Nginx host above configuration: Upload b.jpg to the server
[Email protected] html]# vi/usr/local/nginx/conf/nginx.conf
Location ~. php$ {
Proxy_pass http://192.168.80.101;
}//Transfer PHP dynamic request to 192.168.80.101
[Email protected] html]# RM index.php
[[Email protected] html]# service Nginx restart
Apache Server above configuration:
[Email protected] ~]# cd/usr/local/httpd/htdocs/
[Email protected] htdocs]# VI index.html
<body>
</body>
[Email protected] htdocs]# service httpd restart
Browser output nginx server IP test:
Nginx Server Modification:
[Email protected] html]# vi/usr/local/nginx/conf/nginx.conf
Location ~. *. (gif|jpg|jpeg|png|bmp|swf) $ {
root HTML;
Expires 1d;
}//These static content is read from local
[[Email protected] html]# service Nginx restart
Apache Server above configuration:
[Email protected] htdocs]# vi/usr/local/httpd/htdocs/index.php
<body>
</body>
[Email protected] htdocs]# service httpd restart
Grab bag test:
Lnmp schema--linux7.4+nginx1.13.9+mysql5.7.20+php7.1.10