关于配置
环境
两台虚拟机 都只开放80端口 前端虚拟机服务器运行端口3000 ip:192.168.130.130 后端虚拟机服务器运行端口8090 ip:192.168.130.129
主要是看前端设置,要把api的请求都代理到后端服务器上面去
前端
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 100m;
upstream blog {
server 127.0.0.1:3000;
}
upstream api {
server 192.168.130.129;
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://blog;
}
location /api/ {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://api;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
后端
后端不需要代理的话可以免去,只看前端部分就好
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 100m;
upstream blog {
server 127.0.0.1:8090;
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://blog;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}