Nginx 学习笔记
1. Nginx目录结构
在Linux系统中, nginx默认安装在/usr/local/nginx目录下
(1). conf目录
配置目录
| 文件 | 作用 | 
|---|---|
| nginx.conf | 默认的配置⽂件 | 
| nginx.conf.default | 官方提供的默认配置文件的模板 | 
(2). html目录
默认站点⽬录
| 文件 | 作用 | 
|---|---|
| 50x.html | 错误⻚⾯ | 
| index.html | 默认的⾸⻚ | 
(3). logs目录
日志目录
| 文件 | 作用 | 
|---|---|
| error.log | 记录出错信息的⽇志 | 
| nginx.pid | 记录当前启动的nginx的进程id | 
| access.log | 访问日志 | 
(4). sbin目录
启动目录
| 文件 | 作用 | 
|---|---|
| nginx | nginx启动文件 | 
2. Nginx常用命令
| 命令 | 作用 | 
|---|---|
| ./nginx | 使用默认配置文件启动 | 
| ./nginx -s reload | 使用默认配置文件重新启动 | 
| ./nginx -c 文件绝对路径 | 使用指定配置文件 | 
| ./nginx -s stop | 关闭 | 
3. Nginx默认配置文件
#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
# 事件模块指令,⽤来指定Nginx的IO模型,Nginx⽀持的有select、poll、kqueue、epoll 等。不同的是epoll⽤在Linux平台上,⽽kqueue⽤在BSD系统中,对于Linux系统,epoll⼯作模式是⾸选
events {
	# use epoll;
	# 定义Nginx每个进程的最⼤连接数
	# 对于服务器: 最⼤并发数量 = worker_connections * worker_processes,
 	# 对于反向代理: 最⼤并发数量 = worker_connections * worker_processes/2
 	#因为反向代理服务器,每个并发会建⽴与客户端的连接和与后端服务的连接,会占⽤两个连接
    worker_connections  1024;
}
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;
	# 是否开启⾼效传输模式 on开启 off关闭
    sendfile        on;
	# 减少⽹络报⽂段的数量
    #tcp_nopush     on;
	# 客户端连接保持活动的超时时间,超过这个时间之后,服务器会关闭该连接
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    	
	# 虚拟主机的配置
    server {
    	# 虚拟主机的服务端⼝
        listen       80;
        # ⽤来指定IP地址或域名,多个域名之间⽤空格分开
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
		# URL地址匹配
        location / {
            root   html;
            index  index.html index.htm;
        }
        #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;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}










