我为运行8042的节点应用程序为ngnix设置了反向代理,并且我想为运行在8043上的管理应用程序做同样的事情,但它根本无法正常工作,找不到问题。
这有效,
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
rewrite ^/proj(.*) /$1 break;
proxy_pass http://localhost:8042;
}
}
这不是,两个代码都存在于相同的站点上(可用/默认文件)
server {
listen 8881 default_server;
server_name _;
location /proj-admin {
rewrite ^/proj-admin(.*) /$1 break;
proxy_pass http://localhost:8043;
}
}
答案 0 :(得分:1)
使用以下内容替换/ etc / nginx文件夹中的当前nginx.conf文件,
#worker_processes 2;
events {
worker_connections 1024;
}
http {
sendfile on;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time $upstream_response_time $pipe';
access_log /var/log/nginx/access.log timed_combined;
error_log /var/log/nginx/error.log;
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream api_server {
server 127.0.0.1:8042;
}
upstream admin_server {
server 127.0.0.1:8043;
}
server {
listen 80;
server_name _;
return 404;
}
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://api_server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location /proj-admin {
proxy_pass http://admin_server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
答案 1 :(得分:0)
有人和我一起工作
...
location /api/ {
rewrite /api/(.*)$ /$1 break;
...