ini Nginx app前端/负载均衡器/静态资产缓存(未测试)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ini Nginx app前端/负载均衡器/静态资产缓存(未测试)相关的知识,希望对你有一定的参考价值。

# Number of worker processes. Set it to the number of available CPU cores as a good start value or use 'auto' to autodetect it
worker_processes 4;

# User and group used by worker processes
user www-data www-data;

# Skip superfluous info in the main error log file
error_log /var/log/nginx/error_log error;

# Limit number of files a worker process can open
worker_rlimit_nofile 1024;

pid /var/run/nginx.pid ;

events {
  worker_connections 1024;
}

http {
  server_names_hash_bucket_size 64;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  
  access_log /var/log/nginx/access.log;
  
  sendfile on;
  #tcp_nopush on;
  
  #keepalive_timeout 0;
  keepalive_timeout 65;
  tcp_nodelay on;
  
  gzip on;
  gzip_http_version 1.1;
  gzip_vary on;
  gzip_comp_level 6;
  gzip_proxied any;
  gzip_types text/plain text/css application/json application/x-javascript text/xml   application/xml application/xml+rss text/javascript;  
  gzip_buffers 16 8k; 
  
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

# Nginx app frontend + Load balancer 
upstream projectname {
  server 22.22.22.2:3000;
  server 22.22.22.3:3000;
  server 22.22.22.5:3000;
}
 
server {
  listen 80;
  charset utf-8;

  server_name your-site.com www.your-site.com;
 
  location / {
    proxy_pass http://projectname;
  }
  # Static assets caching
  location ~* \.(css|js|gif|jpe?g|png)$ {
    expires 168h;
    
  }
  # Static assets caching
  location /api {
    expires 10m;
  }
}

# more https://gist.github.com/learncodeacademy/ebba574fc3f438c851ae
# more https://github.com/Stolz/linux-cheat-sheets/blob/master/nginx.md

nginx负载均衡时静态资源无法加载的问题

问题:  配置好nginx负载均衡后,访问项目,发现也没的静态资源无法访问

 

解决:

修改nginx.conf 文件,如下图,从第二行开始换掉即可

 

以上是关于ini Nginx app前端/负载均衡器/静态资产缓存(未测试)的主要内容,如果未能解决你的问题,请参考以下文章

dns + nginx实现负载均衡

nginx+tomcat集群负载均衡(实现session复制)

Nginx作为负载均衡——实战演练

nginx负载均衡时静态资源无法加载的问题

Nginx负载均衡及静态代理

nginx做前端反代负载均衡,后端httpd+tomcat