nginx配置文件记录

nginx.conf 模板以及说明(持续更新中)


#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;


events {  
    worker_connections  1024;   #最大连接数
}


http {
    include       mime.types;
    default_type  application/octet-stream;
	
	#代理服务器集群  upstream  默认为轮询方式,当nginx发现某一个节点挂掉以后,就会将该节点从集群中删除调,当节点回复以后,会将服务继续加入到当前节点中
	upstream  backend {
		server 127.0.0.1:8080 weight = 1;
		server 127.0.0.1:8010 weight = 3;
		server 127.0.0.1:8030 weight = 3 backup;  #当服务全部挂掉以后,才会启用的备份服务
	}	

    #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;
	#配置一个具体的站点,可以配置多个
    server {
        listen       80  default;		#监听端口 default表示默认的
        server_name  localhost;	#设置的域名,客户端访问的域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
			proxy_pass backend;
           # 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;
        #}
    }
	# 一个server对应的是一个服务
	#正向代理
	server{
		listen 80;
		server_name www.abc.com;
		location /baidu {
			proxy_pass http://www.baidu.com; #表示请求转发,如果转发到本地,则只需要开放一个端口即可
		}
		  location /app {
            #proxy_pass http://backend/; #以/结尾表示 当请求具体的路径的时候会访问  http://localhost:8080/xxx   http://localhost:8080/app/user/login->http://localhost:8001/user/login
            proxy_pass http://backend   #当不以/结尾时表示:转发的具体路径为 http://localhost:8080/api/xx  http://localhost:8080/app/user/login->http://localhost:8080/app/user/login
        }
	}
	
	
	server {
		listen 80;
		server_name www.lixc.com *.lixc.com  www.lixc.*   #可以使用通配符,路径匹配原则:1.最大匹配原则,2.左边大于右边 3.谁在上谁优先
		location / {
			root html;
			index index.html index.htm;
		}
		location /old {
			root html;   #如果增加了路径映射,关键字还使用root的话,路径的访问地址会变成 html/old/index.html 会将映射路径添加到root路径后面  xxxx/old/index.html->xxxx/html/old/index.html
		#	alias html;  #如果是alias别名方式,会将old作为html的别名,当路径中有/old时,会将old替换成为html;访问路径为 html/index.html   只能配置在location模块下面  xxxx/old/index.html->xxxx/html/index.html
			index index.html index.htm;
		}
	}
		


    # 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;
    #    }
    #}

}

403 forbidden:
之前的静态资源文件都能访问,当我调整了nginx.conf中的静态文件位置之后就不能访问了,猜测可能是因为没有文件夹的访问权限导致的;
1.要么调整文件夹的权限和所属用户 2,要么调整静态资源文件位置到nginx的目录下面
502 bad gateway:(尚未解决)
再将jar包重启之后 ,发现所有请求到nginx的路径 都返回502,检查nginx的状态为启动状态,查看日志也没有特别明显的提示,服务也都再启动中
不知道为什么会展示这样,百度搜索有的提示是因为代理的服务端stop导致,有的说是因为请求头太大导致 过了一会又自动的好了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值