nginx代理服务器配置

nginx代理服务器配置

需要配置环境需求

1、一台1.1.1.1服务器,一台2.2.2.2服务器

前端包路径在1.1.1.1 /etc/dist 下

后端服务在2.2.2.2 上 暴露端口为9999

2、需求

现在需要访问 1.1.1.1:80访问到2.2.2.2 上面的9999后端服务

3、配置nginx

①:在1.1.1.1上配置

powershell 复制代码
upstream my_server {                                                         
		    server 。2.2.2.2:9999;                                                
		    keepalive 2000;
		}
    server {
        listen       80;
        server_name 1.1.1.1;
        client_max_body_size 1024M;

	    location /substation/ {  
	        proxy_pass http://my_server/substation/;  
	        proxy_set_header Host  $host:$server_port;  
	    }

		location / {
	        root  /etc/dist/; 
		   index index.html;
	        try_files $uri $uri/ /index.html; # 对于单页面应用,这通常很有用  
	    }
    }

	
	
    server {
        listen       9999;
        server_name 1.1.1.1;
        client_max_body_size 1024M;

	    location /substation/ {  
	        proxy_pass http://my_server/substation/;  
	        proxy_set_header Host  $host:$server_port;  
	    }
    }

通过该配置,访问nginx地址http://1.1.1.1.1:80/my的请求会被转发到my_server服务地址http://.2.2.2.2:9999/

相关推荐
千夜啊15 小时前
Nginx 运维开发高频面试题详解
运维·nginx·运维开发
@_@哆啦A梦1 天前
Nginx知识
运维·nginx
繁梦溪2 天前
在Ubuntu子系统中基于Nginx部署Typecho
linux·nginx·ubuntu
千夜啊2 天前
nginx目录结构和配置文件
运维·nginx
苹果醋33 天前
Win10安装MySQL、Pycharm连接MySQL,Pycharm中运行Django
运维·vue.js·spring boot·nginx·课程设计
苹果醋34 天前
MySQL查询优化(三):深度解读 MySQL客户端和服务端协议
java·运维·spring boot·mysql·nginx
清欢渡hb5 天前
使用 Docker + Nginx + Certbot 实现自动化管理 SSL 证书
nginx·docker·自动化
m0_748241235 天前
如何将Vue项目部署至 nginx
前端·vue.js·nginx
躲在没风的地方5 天前
多级缓存(亿级并发解决方案)
java·redis·nginx·缓存·tomcat·springboot
清风细雨_林木木5 天前
Nginx 开发总结
运维·nginx