在nginx配置文件中配置如下
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
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 8083;
server_name 106.55.9.3; #此处设置的是服务器ip
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
location /im {
alias /home/poetry-vue3;
index index.html;
try_files $uri $uri/ /index.html;
}
location ~ /api/ {
fastcgi_buffers 256 128k;
chunked_transfer_encoding off;
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://106.55.9.3:8081;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /socket {
proxy_pass http://127.0.0.1:9324;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 600s;
}
}
}
这里监听了8083的端口,在nginx启动的时候也映射了宿主机的8083:8083端口,
希望能通过8083转发到8081端口做后端的请求,前端请求路径:http://106.55.9.3:8083/api/webInfo
实际后端接口路径是 8081/webInfo
发现无法转发,不知道问题出在哪里,求解答~