nginx编译、安装、日志

  1. gcc安装
    yum install gcc-c++
  2. pcre pcre-devel 安装
    yum install -y pcre pcre-devel
  1. zlib 安装
    yum install -y zlib zlib-devel
  2. OpenSSL安装
    yum install gcc patch libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-debel db4-devel libpcap-devel xz-devel openssl openssl-devel -y
  3. 下载源码包
    wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
  4. 解压缩源码
    tar -zxvf nginx-1.12.0.tar.gz
  5. 进入代码包,安装
    ./configure --prefix=/var/local/nginx/ --with-http_ssl_module --with-http_stub_status_module

     ///var/local/nginx/是安装目录

  6. 编译
    make && make install
  7. Cd 到/var/local/nginx/sbin
  8. ./nginx 运行
  9. 验证配置文件语法是否正确
    /var/local/nginx/sbin/nginx -t
  10. 重启nginx
    /var/local/nginx/sbin/nginx -s reload
  11. 打开nginx

    /var/local/nginx/sbin/nginx -s start

    关闭nginx

    /var/local/nginx/sbin/nginx -s stop
    1. 静态网站配置

    Nginx.conf 主配置文件

    server {
    
     36         listen       80;
    
     37         server_name  localhost;  #域名
    
    42          #这里是nginx的网站配置区域
    
     43         location / {
    
                                #nginx通过root指令,确定nginx网页文件放在哪里
    
     44             root   html;   #指的是nginx安装目录下的一个html文件夹
    
     45             index  index.html index.htm;  #index指的是,首页文件的名字,文件名
    
     46         }
    
     47
    
    52         error_page   500 502 503 504  /50x.html;
    
     53         location = /50x.html {
    
     54             root   html;
    
     55         }

    三 基于多端口的虚拟主机-修改配置文件  复制server

    server {
    
     36         listen       81;
    
     37         server_name  localhost;  #域名
    
    42          #这里是nginx的网站配置区域
    
     43         location / {
    
                                #nginx通过root指令,确定nginx网页文件放在哪里
    
     44             root   html;   #指的是nginx安装目录下的一个html文件夹
    
     45             index  index.html index.htm;  #index指的是,首页文件的名字,文件名
    
     46         }
    
     47
    
    52         error_page   500 502 503 504  /50x.html;
    
     53         location = /50x.html {
    
     54             root   html;
    
     55         }

    四  访问日志

    配置文件 http下打开

    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;

    查看日志 #持续的监测内容变化。

    tail -f /var/local/nginx/logs/access.log

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值