Nginx简单配置

配置文件位置:nginx/conf/nginx.conf
upstream 127.0.0.1 {
  server 127.0.0.1:80 weight=1;
  #目标服务器1的ip地址和端口号	weight权重
  #server 192.168.28.145:80 weight=1;
  #目标服务器2的ip地址和端口号 	weight权重
  server 192.168.28.146:80 weight=1;
  #目标服务器3的ip地址和端口号	weight权重
  #server 192.168.28.136:80 weight=1;
 }
server {
	#监听端口号。访问nginx服务器88端口,会进行反向代理和负载均衡
    listen       88;
    #服务名称,此处填写如www.csdn.net
    server_name  127.0.0.1;
	
    #charset koi8-r;

    #access_log  logs/host.access.log  main;

	#代理ip地址,本机127.0.0.1
    location / {
        proxy_pass http://127.0.0.1;
	}


	location ~* ^.+\.(ico|gif|jpg|jpeg|png)$ {  
		proxy_pass http://127.0.0.1;
         #root       work;  
         proxy_redirect off;
		proxy_set_header Host $host;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 1h;
		proxy_cache_valid 301 1d;
		proxy_cache_valid any 1m;
		expires 30d; 
		proxy_set_header Host $host;  
		proxy_set_header X-Real-IP $remote_addr;  
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    }  
    location ~* ^.+\.(css|js|txt|xml|swf|wav)$ {  
		proxy_pass http://127.0.0.1;
         #root        work;   
         proxy_redirect off;
		proxy_set_header Host $host;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 1h;
		proxy_cache_valid 301 1d;
		proxy_cache_valid any 1m;
		expires 30d;
		proxy_set_header Host $host;  
		proxy_set_header X-Real-IP $remote_addr;  
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    }  
	
    #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;
    #}
}
在配置过程中会出现静态资源加载不完全的情况,这是因为nginx 需要缓存这些资源,如果nginx 缓存设置太小就会出现js文件加载不全的情况,可以通过如下配置,动态更改缓存设置:

​ proxy_buffer_size 512k;

​ proxy_buffers 64 512k;

​ proxy_busy_buffers_size 512k;

在这里插入图片描述

同时静态资源太多,可以采用静态资源缓存到nginx服务器上,其在http 中添加配置如下:

​ proxy_temp_path work;

​ proxy_cache_path work/cache levels=1:2 keys_zone=cache_one:50m inactive=20m max_size=30g;

并且对需要缓存的静态资源添加如下配置:

在这里插入图片描述

官网地址:http://nginx.org/en/download.html
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值