nginx.conf 基础配置

### 全局块开始###

#配置允许运行nginx服务器的用户和用户组
user  nobody;

#配置允许nginx进程生成的worker process 数
worker_processes  1;

#配置nginx服务器运行对错误日志的存放路径
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#配置nginx服务器运行时的pid文件存放路径和名称
pid        logs/nginx.pid;

### 全局块结束###


### events块开始###

events {
    #配置事件驱动模型
	use epoll;
	#配置最大连接数
    worker_connections  1024;
}

### events块结束###



### 全局块结束###


### HTTP块开始###
http {
    # 定义MIME-Type ,查看mime.types文件
    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方式传输
    sendfile        on;
	
    #tcp_nopush     on;

    #配置连接超时时间
    keepalive_timeout  65;

    #gzip  on;

	### server块开始###
	### 配置虚拟主机myServer1###
    server {
	    # 配置监听端口和主机名称(基于名称)
        listen       80;
        server_name  myServer1;

        #charset koi8-r;

        #配置请求处理日志存放路径
		access_log  logs/host.access.log  main;

		# 配置处理/service1/location1 请求的location
        location /service1/location1 {
            root   /myweb;
            index  index1.html;
        }
		
		# 配置处理/service1/location2 请求的location
        location /service1/location2 {
            root   /myweb;
            index  index2.html;
        }

        # 配置错误页面
		error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
	### 配置虚拟主机myServer2###
	   server {
	    # 配置监听端口和主机名称(基于ip)
        listen       8082;
        server_name  192.168.1.3;

        #charset koi8-r;

        #配置请求处理日志存放路径
		access_log  logs/host.access.log;

		# 配置处理/service2/location1 请求的location
        location /service2/location1 {
            root   /myweb;
            index  index2.html;
        }
		
		# 对location的uri进行更改
        location /svr2/loc2 {
            alias /myweb/server2/location2;
            index  index.svr2-loc2.htm;
        }

        # 错误页面404.html 做了重定向
		error_page  404              /404.html;

        location = /404.html {
            root   /myweb;
			index  404.htm;
        }
    }
	### server块结束###

}
### HTTP块结束###

  

posted @ 2017-12-05 09:43  zzhi.wang  阅读(265)  评论(0编辑  收藏  举报