首页 > 技术文章 > Nginx笔记总结一:基本安装和配置

djoker 2017-02-09 13:47 原文

1. Nginx安装
  下载地址和安装依赖包
    http://nginx.org/download/nginx-1.9.14.tar.gz
    yum -y install pcre pcre-devel zlib-devel openssl*
  编译安装
    ./configure --prefix=/usr/local/nginx \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-pcre
  启动,关闭,重启
    /usr/local/nginx/sbin/nginx 启动
    /usr/local/nginx/sbin/nginx -s stop 关闭
    /usr/local/nginx/sbin/nginx -s reload 重启
    /usr/local/nginx/sbin/nginx -t 检查配置
  配置文件
  

user nobody;
  worker_processes 1;
  error_log logs/error.log notice;
  pid logs/nginx.pid;
  events {
    worker_connections 1024;
    use epoll;
  }
  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;
    gzip on;


    upstream proxy1 {
      server 192.168.89.10:180;
    }
    upstream proxy2 {
      server 192.168.89.10:280;
    }


    server {
      listen 80;
      server_name www1.dlab.com;
      location / {
        proxy_pass http://proxy1;
      }
    }


    server {
      listen 80;
      server_name www2.dlab.com;
      location / {
        proxy_pass http://proxy2;
      }
    }
  }

 

推荐阅读