sweli 发表于 2018-11-15 10:02:04

nginx的安装部署

  1.安装依赖包:
  yum install pcre-devel zlib zlib-devel
  2.下载软件
  wget http://nginx.org/download/nginx-1.6.3.tar.gz
  3.添加用户
  useradd nginx -s /sbin/nologin -M
  4.编译安装
  cd /tmp/nginx-1.6.3
  ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.6.3--with-http_ssl_module --with-http_stub_status_module --with-pcre
  make && make install
  ln -s nginx-1.6.3nginx
  5.启动并检查安装结果:
  /usr/local/nginx/sbin/nginx -t
  /usr/local/nginx/sbin/nginx
  # lsof -i :80

  COMMANDPIDUSER   FD   TYPE DEVICE>  nginx   2343root    6uIPv4 191050      0t0TCP *:http (LISTEN)
  nginx   2344 nginx    6uIPv4 # ps uax|grep nginx
  root      23430.00.043112   924 ?      Ss   15:42   0:00 nginx: master process nginx
  nginx   23440.00.1435281500 ?      S    15:42   0:00 nginx: worker process
  root      23840.00.061192   724 pts/1    R+   15:44   0:00 grep nginx191050      0t0TCP *:http (LISTEN)
  # curl http://localhost
  
  
  
  Welcome to nginx!
  6.nginx的配置文件:
  # cat nginx.conf
  usernginx nginx; #set the user of nginx
  worker_processes2; #this number is the count of CPUs
  error_loglogs/error.logcrit; #the level of error log is crit;
  events {
  use epoll;
  worker_connections1024;
  }
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  #log_format name is mymainlog
  log_formatmymainlog'$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';
  sendfile      on;
  keepalive_timeout65;
  server {
  listen       192.168.1.12:8081;
  #set the domain name of server
  server_namewww.mytest12.www;
  location / {
  #set the absolute path of the web site
  root   /data/www;
  indexindex.html index.htm;
  #set the log of this sever
  access_loglogs/access_www.logmymainlog;
  }
  error_page   500 502 503 504/50x.html;
  location = /50x.html {
  root   html;
  }
  }
  server {
  listen       8082;
  server_namewww.mytest12.blog;
  location / {
  root   /data/blog;
  indexindex.html index.htm;
  access_loglogs/access_blog.logmymainlog;
  }
  error_page   500 502 503 504/50x.html;
  location = /50x.html {
  root   html;
  }
  }
  server {
  listen       8083;
  server_namewww.mytest12.bbs;
  location / {
  root   /data/bbs;
  indexindex.html index.htm;
  access_loglogs/access_bbs.logmymainlog;
  }
  error_page   500 502 503 504/50x.html;
  location = /50x.html {
  root   html;
  }
  }
  server {
  listen       8084;
  server_namewww.mytest12.bbs;
  location / {
  stub_status on;
  access_logoff;
  allow 192.168.1.102;
  deny all;
  }
  }
  upstream myserver {
  #该服务为httpd的两个服务
  server 127.0.0.1:9081 weight=10;
  server 127.0.0.1:9080 weight=10;
  }
  server {
  listen       8888;
  server_namewww.mytest2.cn;
  location / {
  proxy_pass http://myserver;
  proxy_set_header X-Forwarded-For $remote_addr;
  #proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
  access_loglogs/access_myserver.log mymainlog;
  }
  }
  }

  # nginx -s>  7.创建测试目录:
  # mkdir /data/{www,bbs,blog}
  # chown -R nginx /data
  8.配置hosts主机名解析测试域名并测试
  9.nginx参数说明:
  # nginx -h
  nginx version: nginx/1.6.3
  Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
  Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing

  -s signal   : send signal to a master process: stop, quit, reopen,>  -p prefix   : set prefix path (default: /usr/local/nginx-1.6.3/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

页: [1]
查看完整版本: nginx的安装部署