nginx.conf 示例配置

1、nginx.conf配置文件:

[[email protected] nginx]# grep -v "#" nginx.conf

user  nginx;    #运行nginx的用户身份

worker_processes  8;  #nginx启动的核心数,一般比物理CPU核心少一个,并且可以做绑定

events {

use epoll;      #定义使用的事件模型

worker_connections  4096;  #每个nginx工作进程的最大连接数

}

http {

include       mime.types;

default_type  application/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_name  node5.a.com;   #虚拟机的主机名

location / {

root   html/www;   #定义用户访问node5.a.com/的时候,针对的服务器上的index.html或index.php,本次放在/opt/nginx/html,里面有个index.htmk默认首页。

index  index.php  index.html index.htm;  #定义支持的页面文件类型

}

}

include  html/*.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.php  index.html index.htm;

#        include  html/*.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首页

[[email protected] b.org]# pwd

/www/b.org

[[email protected] b.org]# ls

Download  index.html

[[email protected] b.org]# cat  index.html

www.b.org

4、测试:

1、访问node5.a.com:

2、访问node5.a.org:

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

时间: 2024-08-30 01:05:42

nginx.conf 示例配置的相关文章

Centos6.10FastDFS_Tracker.conf示例配置

Centos610系列配置 FastDFS_Tracker.conf示例配置 # is this config file disabled # false for enabled # true for disabled disabled = false # bind an address of this host # empty for bind all addresses of this host bind_addr = # the tracker server port port = 221

虚拟主机ip配置,nginx.conf文件配置及日志文件切割

今天粗略整理了一下虚拟主机配置,nginx.conf文件的配置,及日志文件的切割,记录如下: nginx虚拟主机配置:1.IP地址配置,2.绑定ip地址和虚拟主机详情:1.ip地址的配置:ifconfig eth0 192.168.0.15 netmast 255.255.255.0虚拟ip及对应server块基本配置:ifconfig eth0:1 192.168.0.180 broadcast 192.168.0.255 netmask 255.255.255.0ifconfig eth0:

Nginx配置文件(nginx.conf)配置详解

Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍于CPU. error_log  logs/error.log; error_log  logs/error.log  notice; error_log  logs/error.log  info; 错误日志:存放路径. pid logs/nginx.pi

nginx.conf中配置laravel框架站点

nginx.conf配置如下: user nginx nginx;worker_processes 4; error_log logs/error.log error; pid logs/nginx.pid;worker_rlimit_nofile 102400; events { use epoll; worker_connections 1024;} http { include mime.types; default_type application/octet-stream; log_f

Nginx 1.10.1 版本nginx.conf优化配置及详细注释

Nginx 1.10.1 的nginx.conf文件,是调优后的,可以拿来用,有一些设置无效,我备注上了,不知道是不是版本的问题,回头查一下再更正. #普通配置 #==性能配置#!异常配置 #运行用户 user nobody; #pid文件 pid logs/nginx.pid; #==worker进程数,通常设置等同于CPU数量,auto为自动检测 worker_processes auto; #==worker进程打开最大文件数,可CPU*10000设置 worker_rlimit_nofi

Nginx之二:nginx.conf简单配置(参数详解)

vim /usr/local/nginx/conf/nginx.conf #user  nobody; #程序运行使用账户 worker_processes  1; #启动的进程,通常设置成和cpu的数量相等 #全局错误日志级PID文件 #error_log  logs/error.log; #error_log  logs/error.log  notice; #error_log  logs/error.log  info; #pid        logs/nginx.pid; event

2、Nginx配置文件nginx.conf的配置详解

前面Nginx安装配置文件中简单的解释了nginx.conf配置文件中几个指令的含义,这篇文章内容将对这些指令的用法作出详细的解释. 先看看配置文件的内容: user  nginx; worker_processes  4; error_log  /var/log/nginx/error.log warn; pid        /var/run/nginx.pid; events {     worker_connections  1024; } http {     include     

nginx.conf简单配置

前言: 最简单的nginx.conf配置文件,纯干货,不解释! 主配置文件 [[email protected] application]# cat nginx/conf/nginx.conf worker_processes  1; error_log  logs/error.log error; events {     worker_connections  1024; } http {     include       mime.types;     default_type  app

nginx使用手册--nginx.conf文件配置详解

#运行用户 user nobody; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; #工作模式及连接数上限 events { #epoll是多路复用IO(I/O Multiplexing)中的一种方式, #仅