nginx配置反向代理

nginx配置反向代理

# 运行用户
user  nginx;
# 工作者进程
worker_processes  1;

## 日志
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


## 工作模式和连接数上限
events {
    worker_connections  1024;
}

# 设定http服务器
http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

#    include /etc/nginx/conf.d/*.conf;

server {
    listen       80;
    server_name  .a.com;

    charset utf-8;
    access_log  /var/log/a.com.access.log;

location / {
    try_files /_not_exists_ @backend;
}

    location @backend {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host            $http_host;

        proxy_pass http://127.0.0.1:9080;
    }
}

}

nginx配置(conf/nginx.conf)

  • nginx监听80端口
server {
        listen       80;
        server_name  你的域名;

        #后台服务配置,配置了这个location便可以通过http://域名/jeecg-boot/xxxx 访问        
        location ^~ /jeecg-boot {
            proxy_pass              http://127.0.0.1:8080/jeecg-boot/;
            proxy_set_header        Host 127.0.0.1;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题
        location / {
            root   html;
            index  index.html index.htm;
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.html?s=$1 last;
                break;
            }
        }
    }
原文地址:https://www.cnblogs.com/jiftle/p/12305638.html