Nginx网页服务基础及配置文件

目录

  • 一、Nginx概述
  • 二、配置文件
    • 1、手工编译安装
    • 2、运行控制
    • 3、配置文件
  • 三、Nginx统计页面
  • 四、访问控制:

一、Nginx概述

  • 一款高性能,轻量级web服务软件
    稳定性高
    系统资源消耗低
    对http并发连接的处理能力高(高并发处理)
    单台物理服务器可支持30000-50000个并发请求

二、配置文件

1、手工编译安装

yum -y install gcc gcc-c++ pcre-devel zlib-devel
useradd -M -s /sbin/nologin nginx
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make && make install

2、运行控制

Nginx -t   ##检查配置文件
killall -s HUP Nginx   ##重载配置
killall -s QUIT Nginx  ##退出进程
将Nginx添加为系统服务
vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description:Nginx Service Control Script
PROG="/usr/localinx/sbininx"
PIDF="/usr/localinx/logsinx.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

3、配置文件

  • 全局配置
#user nobady;       ##管理用户
worker_processes 1;  ##进程
#error_log log/error.log;   ##错误日志
#pid	logs/nginx.pid;   ##pid号文件
  • I/O事件配置
events {            ##一个进程包含多个线程的工作模式
  use epoll;
  worker_connections 4096;
}
  • 主配置文件/usr/local/nginx/conf/nginx.conf
http {    ##协议字段
  ......
  access_log logs/access.log main;
  sendfile  on;
  ......
  server{               ##服务字段
    listen  80;
    server_name www.test.com;
    charset utf8;
    location / {           ##目录字段
       root html;
       index index.html index.php;
     }
     error_page 500 502 503 504 /50x.html;    ##内部错误反馈页面
     location = /50x.html {    ##错误页面配置
        root html;      
      }
      ......
      location / {
       root html;
       index index.html index.php;
     }
     ......
   }
}

三、Nginx统计页面

手工编译安装
yum -y install gcc gcc-c++ pcre-devel zlib-devel
cd nginx
useradd -M -s /sbin/nologin nginx
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make && make install
[root@promote /]# vim /usr/local/nginx/conf/nginx.conf
location /status {
  stub_status on;
  access_log off;
}  

Nginx网页服务基础及配置文件_第1张图片
Nginx网页服务基础及配置文件_第2张图片

四、访问控制:

yum -y install httpd
which htpasswd
htpasswd -c /usr/local/nginx/passwd.db tom
chown nginx /usr/local/nginx/passwd.db
chmod 400 /usr/local/nginx/passwd.db
修改配置文件
vim /usr/local/nginx/conf/nginx.conf
添加
location / {
  auth_basic "secret";
  auth_basic_user_file /usr/local/nginx/passwd.db;
  root html;
  indedx index.html index.php;
}
登录时需要身份验证

Nginx网页服务基础及配置文件_第3张图片
ip地址访问拒绝:

server {
 location / {
          deny 192.168.195.200;
          allow all;
          root html;
          index index.html index.html;
        }
}

Nginx网页服务基础及配置文件_第4张图片

你可能感兴趣的:(nginx,网页服务)