http://nginx.org/en/download.html
service firewalld stop
systemctl disable firewalld
yum -y install
pcre-devel
zlib-devel
useradd -M -s /sbin/nologin nginx
tar xzvf nginx-1.13.7.tar.gz -C /usr/src/
cd /usr/src/nginx-1.13.7
./configure
–prefix=/usr/local/nginx
–user=nginx
–group=nginx
–with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
nginx -t //配置文件语法检查
nginx //启动服务
killall -1 nginx //安全重启
killall -3 nginx //停止服务
-------制作管理角本--------
vi /etc/init.d/nginx
#!/bin/bash
#chkconfig: 35 99 20
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case “$1” in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo “Usage: $0 {start|stop|restart|reload}”
exit 1
esac
exit 0
chmod +x /etc/init.d/nginx
chkconfig --add nginx
vi /usr/local/nginx/conf/nginx.conf
user nginx nginx;
error_log logs/error.log info;
----日志级别—
debug info notice warn error crit //向上记录
events {
use epoll; //新增此行 默认使用select/poll
worker_connections 10240; //表示1个工作进程允许10240个连接。
log_format main //定义日志格式 把前面的#号去掉
ulimit -n 65500//查看和更改系统本地打开资源数
ulimit -n 65500 >> /etc/rc.local
—配置统计功能----
location ~ /status {
stub_status on;
access_log off;
} //在server 模块里的error_page 上面增加
service nginx reload
cat /usr/local/nginx/logs/access.log
http://IP/status //当前的活动连接数,已处理的连接数,成功的TCP握手次数,已处理的请求数。
-----以下配置nginx的验证功能—
yum install httpd-tools
htpasswd -c /usr/local/nginx/passwd.db jack
chmod 400 /usr/local/nginx/passwd.db
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;
}
service nginx restart
http://192.168.80.181/ //需要验证才能访问
-------以下配置虚拟主机功能-------
—基于域名----------IP和端口都相同但是域名不相同—在最后一行上面插入–
vi /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.aa.com;
charset utf-8;
access_log logs/aa.access.log main;
location / {
root /var/www/aa;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
}
-------基于IP的–端口号相同但是IP不相同—
listen 192.168.80.193:80;
—基于端口的---------IP相同但是端口号不相同-----
listen 192.168.80.193:8080; //在配置文件头部
--------------以下是安装MYSQL-----http://mirrors.sohu.com/mysql/---
---------------以下安装mysql------------------------
yum -y install
ncurses
ncurses-devel
bison
cmake
useradd -s /sbin/nologin mysql
tar xf mysql-boost-5.7.20.tar.gz
cd mysql-5.7.20/
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-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
-DWITH_BOOST=boost
-DWITH_SYSTEMD=1
make && make install
chown -R mysql.mysql /usr/local/mysql/ 也可mysql:mysql
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
chown mysql:mysql /etc/my.cnf
echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH’ >> /etc/profile
echo ‘export PATH’ >> /etc/profile
source /etc/profile
cd /usr/local/mysql/
bin/mysqld
–initialize-insecure
–user=mysql
–basedir=/usr/local/mysql
–datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306
systemctl enable mysqld
mysqladmin -u root -p password “abc123” //给root账号设置密码
mysql -u root
-----------------以下安装PHP-----------
yum -y install
libjpeg
libjpeg-devel
libpng libpng-devel
freetype freetype-devel
libxml2
libxml2-devel
zlib zlib-devel
curl curl-devel
openssl openssl-devel
tar xjvf php-7.1.10.tar.bz2
cd 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
–enable-mbstring
–enable-xml
–enable-session
–enable-ftp
–enable-pdo
–enable-tokenizer
–enable-zip
–enable-fpm
make && make install
cp php.ini-development /usr/local/php/lib/php.ini
vi /usr/local/php/lib/php.ini
mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai
/usr/local/php/bin/php -m //验证安装的模块
-----------配置及优化FPM模块--------
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
cd /usr/local/php/etc/
vi php-fpm.conf
pid = run/php-fpm.pid
;user = nginx
;group = nginx
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
netstat -anpt | grep 9000
ln -s /usr/local/php/bin/* /usr/local/bin/
ps aux | grep -c “php-fpm” //结果
-----更新启动脚本----------
vi /etc/init.d/nginx
#!/bin/bash
chkconfig: 35 99 20
description: 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 “$1” in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo “Usage: $0 {start|stop|restart|reload}”
exit 1
esac
exit 0
--------以下是让nginx支持PHP功能--------
vi /usr/local/nginx/conf/nginx.conf
location ~ .php$ {
root /var/www/aa;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/aa$fastcgi_script_name; //注意目录名称
include fastcgi_params;
}
vi /var/www/aa/index.php
<?php phpinfo(); ?>在网页测试“http://192.168.80.193/index.php”
--------下面测试数据库工作是否正常-----
mysql -u root -p
CREATE DATABASE bbs;
GRANT all ON bbs.* TO ‘bbsadm’@’%’ IDENTIFIED BY ‘admin123’;
GRANT all ON bbs.* TO ‘bbsadm’@‘localhost’ IDENTIFIED BY ‘admin123’;
flush privileges;
DROP DATABASE bbs;删除数据库bbs
vi /var/www/aa/index.php
<?php $link=mysqli_connect('192.168.80.181','bbsadm','admin123'); if($link) echo "Success!!
"; else echo "Fail!!"; ?>在网页测试“http://192.168.80.193/index.php”
—以下安装论坛------
unzip Discuz_X3.2_SC_UTF8.zip -d /tmp
cd /tmp
cp -r upload/ /usr/local/nginx/html/bbs 放到nginx的网页根目录中正常生效
cd /usr/local/nginx/html/bbs
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
http://IP/bbs/install
http://IP/bbs/admin.php //管理后台
cd /var/www/aa/bbs
mv install/ install.lock
chmod 600 install.lock/
-----------配置动静分离--------------
vi /etc/nginx.conf //还原配置文件修改server下配置
server_name www.bt.com;
charset utf-8;
开启日志相关的配置
错误日志
日志格式
访问日志
-------在location /下新增--------
location ~ .php {
proxy_pass http://192.168.80.182:80;
} //把PHP动态请求转给192.168.80.182
-------以上是动态分离配置------
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
root html;
expires 1d;
} //这些静态内容从本地读取
--------在index.php中加入下面内容测试-----
![](http://192.168.80.181/a.jpg)
抓包测试