什么是NGINX
Nginx是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。 优点: (1)更快 (2)高扩展性,跨平台 (3)高可靠性:用于反向代理,宕机的概率微乎其微 (4)低内存消耗 (5)单机支持10万以上的并发连接 (6)热部署 (7)最自由的BSD许可协议 缺点: (1)相对于apache rewrite没有Apache强大 (2)模块比Apache要少 (3)相对于Apache的bug多点 (4)没有apache稳定 (5)对PHP的支持需要配置其他后端
实验 安装nginx
yum
-y install gcc gcc
-c+
+ make pcre
-devel expat
-devel perl zlib
-devel
tar xzvf nginx
-1
.15
.9
.tar
.gz
useradd
-s
/sbin
/nologin
-M nginx
cd
/opt
/nginx
-1
.15
.9
/
./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
/
ls -l
/usr
/local
/sbin
/nginx
nginx
-t
nginx
netstat
-anpt
| grep nginx
yum
-y install lynx
lynx 127
.0
.0
.1
killall
-s QUIT nginx
vim
/lib
/systemd
/system
/nginx
.service
[Unit]
Description=nginx
After=network
.target
[Service]
Type=forking
PIDFile=
/usr
/local
/nginx
/logs
/nginx
.pid
ExecStart=
/usr
/local
/nginx
/sbin
/nginx
ExecReload=
/usr
/bin
/kill -s HUP
$MAINPID
ExecStop=
/usr
/bin
/kill -s QUIT
$MAINPID
PrivateTmp=true
[Install]
WantedBy=multi
-user
.target
chmod 754
/lib
/systemd
/system
/nginx
.service
systemctl enable nginx
.service
systemctl
start nginx
netstat
-anutp
|grep nginx
安装MySQL
useradd
-s
/sbin
/nologin mysql
tar xf mysql
-boost
-5
.7
.20
.tar
.gz
yum
-y install \
ncurses \
ncurses
-devel \
bison \
cmake
cd
/opt
/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
-j3 && make install
chown
-R mysql:mysql
/usr
/local
/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
/lib
/systemd
/system
/
systemctl enable mysqld
systemctl
start mysqld
systemctl status mysqld
netstat
-ntap
|grep 3306
mysqladmin
-u root
-p password
"abc123"
mysql
-u root
-p
安装PHP
tar xf php
-7
.1
.10
.tar
.bz2
yum
-y install \
libjpeg \
libjpeg
-devel \
libpng \
libpng
-devel \
freetype \
freetype
-devel \
libxml2 \
libxml2
-devel \
zlib \
zlib
-devel \
curl \
curl
-devel \
openssl \
openssl
-devel
cd php
-7
.1
.10
./configure \
--prefix=
/usr
/local
/php \
--with
-apxs2=
/usr
/local
/httpd
/bin
/apxs \
--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
make && make install
cp php
.ini
-development
/usr
/local
/php
/lib
/php
vi
/usr
/local
/php
/lib
/php
.ini
……省略部分
mysqli
.default_socket =
/usr
/local
/mysql
/mysql
.sock
//后面填入连接文件路径
……省略部分
date
.timezone = Asia
/Shanghai 后面写入上海时区(注意前面的”
;”分号要删去)
……省略部分
cd
/usr
/local
/php
/etc
/
cp php
-fpm
.conf
.default php
-fpm
.conf
vi php
-fpm
.conf
[global]
; Pid file
; Note: the default prefix is
/usr
/local
/php
/var
; Default Value: none
pid = run
/php
-fpm
.pid
……省略部分
cd php
-fpm
.d
/
cp www
.conf
.default www
.conf
/usr
/local
/php
/sbin
/php
-fpm
-c
/usr
/local
/php
/lib
/php
.ini
/usr
/local
/php
/sbin
/php
-fpm
-c
/usr
/local
/php
/etc
/php
.ini
-y
/usr
/local
/php
/etc
/php
-fpm
.conf
-t
/usr
/local
/php
/sbin
/php
-fpm
-t
netstat
-anupt
| grep 9000
ln
-s
/usr
/local
/php
/bin/
* /usr
/local
/bin
/
cd
/usr
/local
/nginx
/conf
/
vi nginx
.conf
location ~ \
.php$
{
root html
;
fastcgi_pass 127
.0
.0
.1:9000
;
fastcgi_index index
.php
;
fastcgi_param SCRIPT_FILENAME
/usr
/local
/nginx
/html
$fastcgi_script_name;
include fastcgi_params
;
}
systemctl stop nginx
.service
systemctl
start nginx
.service
cd
/usr
/local
/nginx
/html
/
mv index
.html index
.php
vim index
.php
<?php
phpinfo
();
?>
访问http://20.0.0.114/index.php
常见问题: 这时候解决办法 vi /usr/local/nginx/conf/nginx.conf