Nginx配置文件

在linux下安装就不说了,和别的软件都差不多:wget压缩包–>解压–>./configure–>make–>make install,网上教程也非常多。

主要看一下配置文件:

#定义worker进程的运行用户,nobody也是一个linux用户,一般用于启动程序,没有密码。如果想自定义用户的话可以改,不过没必要
user nobody;

#worker进程数,通常等于CPU核心数或者核心数的二倍,虚拟机只分了一个核心就用默认的1了。
worker_processes 1;

#全局错误日志定义类型,[ debug | info | notice | warn | error | crit ],默认是error
error_log /usr/local/nginx/logs/error.log;

#进程pid文件,里面就一个进程号,记录每次启动的pid
pid logs/nginx.pid;

#配置工作模式和连接数
event {
	# 配置每个worker进程连接数上限,nginx支持的总连接数就等于worker_connections * worker_processes
	# 比如现在这么配并发上限就只有1024.
	# 这个值的取值上限是65535
	worker_connections 1024;
}
http {
	# 配置nginx支持哪些多媒体类型,可以在conf/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        on; # 开启高效文件传输模式
    #tcp_nopush     on;	# 防止网络阻塞

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

    #gzip  on; # 开启gzip压缩输出,上线的话基本都要开,可以让IO流更小一些,响应也更快
-----------------------------------------------------------------------------------------	
	# 配置虚拟主机
    server {
    	# 如果配置多个server,那么它们的端口号和服务名不能完全相同
    	listen       80; # 配置监听端口 
        server_name  localhost; # 配置服务名

        #charset koi8-r; # 配置字符集,默认utf-8,不用动

        #access_log  logs/host.access.log  main; # 虚拟主机的访问日志,上面的是不管访问那个虚拟主机都会记录

		# 默认匹配 / 请求,当访问路径中有 / ,就会被该location匹配到并进行处理
		# 比如现在nginx启动了,虚拟机的ip为192.168.3.28,在浏览器中访问http://192.168.3.28(:80),就被这条匹配规则
		# 拦截,跳转到html目录下的index.html,和tomcat的欢迎页面一个道理
        location / {
        	# root是配置服务器的默认网站根目录位置,默认为nginx安装目录下的html目录
            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;
    #    }
    #}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值