uyfrjk 发表于 2018-11-14 06:11:24

nginx.conf 示例配置

  1、nginx.conf配置文件:
  # grep -v "#" nginx.conf
  usernginx;    #运行nginx的用户身份
  worker_processes8;#nginx启动的核心数,一般比物理CPU核心少一个,并且可以做绑定
  events {
  use epoll;      #定义使用的事件模型
  worker_connections4096;#每个nginx工作进程的最大连接数
  }
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  server_tokens off;
  keepalive_timeout 65;
  server_names_hash_max_size 1024;
  gzip on;
  gzip_proxied any;
  gzip_min_length 1000;
  gzip_comp_level 4;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  gzip_static on;
  server {   #定义一个server,相当于apace的虚拟主机
  listen       80;#定义改虚拟主机监听的端口
  server_namenode5.a.com;   #虚拟机的主机名
  location / {
  root   html/www;   #定义用户访问node5.a.com/的时候,针对的服务器上的index.html或index.php,本次放在/opt/nginx/html,里面有个index.htmk默认首页。
  indexindex.phpindex.html index.htm;#定义支持的页面文件类型
  }
  }
  includehtml/*.conf;   #这个是重点,相当于加载html/任何以.conf结尾的文件,可以方便定义虚拟主机为名称的配置文件,这样可以简化配置,且方便管理多个虚拟主机文件,而html具体路径是 /opt/nginx/html。
  }
  2、/opt/nginx/html:里面有三个文件和一个目录如下:
  1).50x.html:nginx自定义的服务器内部错误首页:
  2)index.html:在nginx.conf定义的node5.a.com的访问路径文件
  3)node5.a.org.conf:在nginx.conf配置文件定义引用的.conf文件,这样为每个虚拟机主机都创建一个配置文件,更加模块化,期内容如下:
  server {
  listen 80;
  server_name node5.a.org;
  location /{
  root/www/b.org;   #定义node.a.org在服务器的访问文件路径:
  index index.phpindex.html index.htm;
  #      includehtml/*.conf;
  location /Download/ {   #自定义一个站点,即访问node5.a.org/Download的路径。
  root /www/b.org; #定义访问node5.a.org/Download其实是访问的服务器的/www/b.org/Download。
  autoindex on;
  }
  }
  }
  ~
  4)www:是nginx.conf定义的node5.a.com的文件爱你所在目录
  3.为node5.a.org创建/www目录和/www下的Download目录及index.html首页
  # pwd
  /www/b.org
  # ls
  Downloadindex.html
  # catindex.html
  www.b.org
  4、测试:
  1、访问node5.a.com:

  2、访问node5.a.org:

  3、访问node5.a.org/Download:


页: [1]
查看完整版本: nginx.conf 示例配置