nginx的反向代理解决前端跨域问题

#运行nginx所在的用户名和用户组
#user  www www;

#启动进程数,一般为cpu*2
worker_processes 1;
#全局错误日志及PID文件
error_log logs/nginx_error.log  crit;

pid        nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.

worker_rlimit_nofile 65535;
#工作模式及连接数上限
events
{
  use select;
  worker_connections 65535;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http
{
  #设定mime类型
  include       mime.types;
  default_type  application/octet-stream;
      
  sendfile on;
  keepalive_timeout 60;
  client_max_body_size 2m;
  gzip on;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

  server {
      listen       8094;
      server_name  localhost;
      #charset koi8-r;

      #access_log  logs/host.access.log  main;
      #本地前端文件路径
      location / {
      
          root   E:/AppServ/www/nginx-M/html;
          index  index.html index.htm;
      }
      #/apis为后台项目访问路径
      location /apis {
        rewrite  ^.+apis/?(.*)$ /$1 break;
        include  uwsgi_params;
        #目标服务器
        proxy_pass    http://192.168.1.121:8380;
     }
  }
}

猜你喜欢

转载自blog.csdn.net/lin252552/article/details/82493302