Linux 6.5 部署LNMP之Nginx 服务

在个网站服务区软件中,除了Apache HTTP Service 外,还有一款轻量级别HTTP服务软件---Nginx
可以参考我之前写的LAMP大致差不多

  • 安装需要的环境
  • yum install gcc gcc-c++ pcre pcre-devel zlib-devel -y
  • yum remove httpd -y 卸载原有的apache
  • useradd -M -s /sbin/nologin nginx 创建指定组-s表示指定用户所用的shell,此处为/sbin/nologin,表示不登录。
    -M表示不创建用户主目录。
    -g表示指定用户的组名为mysql。
  • tar xzvf nginx-1.6.0.tar.gz -C /opt
  • cd /opt/nginx-1.6.0/
  • ./configure \
    --prefix=/usr/local/nginx \
    --user=nginx \
    --group=nginx \
    --with-http_stub_status_module //开启stub_status状态统计模块//
  • make && make install
  • ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //让系统识别命令
  • 此时就可以启动服务但不是service nginx start 这样 而是
  • -----检查、启动、重启、停止--------
  • nginx -t //检查
  • nginx //启动
  • killall -1 nginx //重启
  • killall -3 nginx //停止
  • -------制作管理角本--------
  • vim /etc/init.d/nginx
  • #!/bin/bash
  • #chkconfig: - 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
  • service nginx start 这个时候就可以用了
  • 也可以访问
  • -----------配置统计页面----

  • cd /usr/local/nginx/conf
  • 为了保险可以重命名一个然后在过滤出# ZAI 在生产新的配置文件 或者重命名原先的配置文件在复制过来
  • 这个看个人
  • vim nginx.conf
  • 在47 行插入
  • location ~ /status {
    stub_status on;
    access_log off;
    }
  • location ~ /status { //访问位置为/status
    stub_status on; //打开状态统计功能
    access_log off; //关闭此位置的日志记录
    }

  • service nginx reload 重新加载服务
  • 就可以看访问记录
  • Linux 6.5 部署LNMP之Nginx 服务
  • Linux 6.5 部署LNMP之Nginx 服务
  • Linux 6.5 部署LNMP之Nginx 服务
  • ------------配置虚拟主机--------
  • 为其创建目录和首页
  • mkdir -p /var/www/accp
  • mkdir -p /var/www/benet
  • echo "this is accp" > /var/www/accp/index.hkml
  • echo "this is benet" > /var/www/benet/index.hkml
  • 安装域名解析
  • 若解析不出来修改DNS解析的主配置文件监听端口两个设置为any
  • Linux 6.5 部署LNMP之Nginx 服务
    Linux 6.5 部署LNMP之Nginx 服务
    Linux 6.5 部署LNMP之Nginx 服务
    ------------------身份验证访问---------------------------------
  • htpasswd -c /usr/local/nginx/passwd.db zhangsan 使用htpasswd 工具时 必须制定用户数据文件位置,添加-c 选项表示新建此文件。更具提示输入密码
  • chown nginx /usr/local/nginx/passwd.db 指定组
  • chmod 400 /usr/local/nginx/passwd.db 修改权限只有管理员和组的人员查看
  • cd /usr/local/nginx/conf/
  • 修改主配置文件
  • vim nginx.conf
  • 因为它运行的时候是自上而下的检要写在前面
  • 重启服务
  • Linux 6.5 部署LNMP之Nginx 服务
  • -------------访问控制---------
    vim /usr/local/nginx/conf/nginx.conf
    44行上面插入 deny 192.168.100.20;
    allow all;
    Linux 6.5 部署LNMP之Nginx 服务

猜你喜欢

转载自blog.51cto.com/13660858/2129288
今日推荐