Ngnix入门之nginx.conf解读

Ngnix入门之nginx.conf解读


最近相当感兴趣与nginx这个web服务器,所以决定搞搞,尤其是他的这个配置文件相当让我感兴趣,也写个博客作为我的笔记,话不多说上配置文件

#user  nobody; #配置Worker进程运行用户,主进程Master
worker_processes  1; #配置工作进程数目,根据硬件调整,通常等于CPU数量或者2倍于CPU数量

#error_log  logs/error.log;#配置全局错误日志及 类型,[debug | info | notice | warn | error | crit],默认是error
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;#配置进程的PID
###分割线===============================================以上为基本配置

#配置工作模式和连接数
events {
   ##use epoll; 优化参数后期大型架构可选择配置
    worker_connections  1024; #配置每个worker进程连接数上限,Nginx支持的总连接数就等于worker_processes * worker_connections
}		##worker_connections上限最大可上限为55535

####===============================================
#配置http服务器,利用它反向代理功能提供负载均衡支持
http {
    include       mime.types;#配置nginx支持哪些多媒体类型,可以在conf/mine.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日志及存放路径,并使用上面定义的main日志格式
    #access_log  logs/access.log  main;

    sendfile        on;#开启高效文件传输模式(优化参数)
    #tcp_nopush     on;#防止网络阻塞(优化参数)开启优化网络

    #keepalive_timeout  0;
    keepalive_timeout  65; #长连接超时时间,单位是秒(超时时间)

    #gzip  on; #开启gzip压缩输出
	####------------------------------以上基本配置
	
	#配置虚拟主机
    server {
        listen       80; #配置监听端口就是端口80端口
        server_name  localhost; #配置服务名

        #charset koi8-r; #配置字符集(koi8-r俄罗斯字符集)

        #access_log  logs/host.access.log  main; #配置本虚拟主机的访问日志,main指日志格式
		#默认的匹配斜杠/的请求,当访问路径中有斜杠/,会被该location匹配到并进行处理
        location / {
            root   html; #root是配置服务器的默认网站根目录位置,默认为nginx安装主目录下的html目录
            index  index.html index.htm;#配置首页文件的名称
        }

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

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html; #配置50x错误页面
		#等号精确匹配
        location = /50x.html {
            root   html;
        }
		#PHP 脚本请求全部转发到Apache处理
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ { #指的后缀为php时进行匹配
        #    proxy_pass   http://127.0.0.1;
        #}
		#PHP 脚本请求全部转发到FastCGI处理
        # 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;
        #}
		#禁止访问 .htaccess 文件
        # 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服务(安全的网络传输协议,加密传输,端口默认443) http明文传输端口默认80,一般运维来配置
    # 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;
    #    }
    #}

}

后续还会出nginx五大应用 静态网站、负载均衡、静态代理、动静分离、虚拟主机

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值