实验环境
centos7
iptables关闭
selinux关闭
nginx服务器
nginx是个高性能、企业常用的web服务器
apache和nginx相比,nginx的安装、配置、管理等比较方便
lnmp和lamp架构
lnmp -> linux + nginx + mysql + php (主流php开发架构)
lamp -> linux + apache + mysql + php
nginx的下载
http://nginx.org/en/download.html
1: nginx的编译安装
yum install -y gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel
cd /usr/local/src
wget 'http://nginx.org/download/nginx-1.14.0.tar.gz'
tar -zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_stub_status_module
make
make install
2: nginx的安装检查
ll -h /usr/local/nginx/
drwxr-xr-x. 2 root root 4.0K Aug 11 10:38 conf #配置文件
drwxr-xr-x. 2 root root 4.0K Aug 11 10:38 html #存放网站文件
drwxr-xr-x. 2 root root 4.0K Aug 11 10:38 logs #存放日志文件
drwxr-xr-x. 2 root root 4.0K Aug 11 10:38 sbin #存放程序
/usr/local/nginx/sbin/nginx -v #验证安装,输出版本
/usr/local/nginx/sbin/nginx -V #查看nginx的编译参数,网站搬家的时候,得看一下nginx的编译参数
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #看个人需要
3: nginx的管理
/usr/local/nginx/sbin/nginx -t #检查配置
/usr/local/nginx/sbin/nginx #启动nginx,观察进程和端口
/usr/local/nginx/sbin/nginx -s stop #关闭nginx,观察进程
/usr/local/nginx/sbin/nginx -s reload #平滑重载nginx配置,改一下worker数
4: nginx加入systemctl管理/usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
5: 使用systemctl管理nginx
systemctl enable nginx #开机启动nginx
systemctl start nginx #启动nginx
systemctl stop nginx #关闭nginx
6: 使用浏览器访问一下网站是否正常
注意防火墙需要放行或者关闭
注意selinux需要关闭