web网站服务--Nginx

本文详细介绍Nginx的安装步骤,包括依赖包安装、用户组创建、源码编译安装等过程,并提供了Nginx的基本配置示例,如全局配置、I/O事件配置和HTTP配置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装及运行

1.编译安装Nginx
Nginx的运行及配置需要pcre、zlib的开发包,以便提供相应的库和头文件

yum -y install pcre-devel zlib-devel

2.创建运行用户、组

useradd -M -s /sbin/nologin nginx

3.编译安装Nginx

tar xzf nginx-*.tar.gz -C /usr/src
cd /usr/src/nginx-*
./configure  --prefix=/usr/local/nginx  --user=nginx  --group=nginx  --with-http_stub_status_module
make && make insatll

http_stub_status_module
模块以支持状态统计,便于查看服务器的连接信息

4.优化路径和控制服务

 ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin
 killall  -s  HUP  nginx                 //重载服务
 killall  -s  QUIT  nginx                //关闭服务

配置文件

1.全局配置

#user  nobody;                             //运行用户 默认为nobody
worker_processes  1;                       //工作的进程数量,可以根据cpu核心总数来指定工作进程数
#error_log  logs/error.log;                //错误日志文件的位置
#pid        logs/nginx.pid;                //PID文件的位置`

2.I/O事件配置

events {
    use epoll                                     //使用epoll模型
    worker_connections  4096;                     //每个进程处理4096个进程连接
}

3.HTTP配置

http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format main  '$remote_addr - $remote_user [$time_local] "$request" ' //去掉前面的#
                     '$status $body_bytes_sent "$http_referer" '  //去掉前面的#
                     '"$http_user_agent""$http_x_forwarded_for"'; //去掉前面的#

    access_log  logs/access.log  main; //去掉前面的#,访问日志位置
    sendfile        on;                //去掉前面的#,支持文件发送(下载)
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;             //连接保持超时
    #gzip  on;
 server {
        listen       80;                           
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
  location / {
        root   html;
        index  index.html index.htm;
        }
  location / status{                   //访问位置为/status
        stub_status on;                //打开状态统计功能
        access_log off;                //关闭此位置的日志记录
        }

        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
            }

配置完后访问http://网站/status可以查看访问状态统计

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值