我有一个运行 NGINX 的 CentOS 服务器,监听 80 和一个在 8080 上为应用程序服务的数据库。我希望能够键入
并让它实际访问
http://example.com:8080/apex/abc或http://localhost:8080/apex/abc
我已经使用了这个位置配置
location /dev {
proxy_pass http://example.com:8080/apex;
}
但是,当我尝试时,显示的 url 是
该页面未找到,日志显示:
2018/06/14 12:51:33 [error] 7209#0: *2067 open()
"/usr/share/nginx/html/apex/apex" failed (2: No such file or directory),
client: 124.157.113.187, server: _, request: "GET /apex/apex HTTP/1.1", host: "example.com"
看起来有两件奇怪的事情正在发生
1) 尽管使用了 proxy_pass,但仍在使用端口 80 而不是 8080
2)为什么apex是两次“/apex/apex/”
请帮忙 :)
从配置文件中添加整个服务器块:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /dev {
proxy_pass http://example.com:8080/apex;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
更新 - 有关可能有帮助的应用程序的更多信息
该应用程序是 Oracle Application Express (APEX),它在端口 8080 上进行侦听。URL 的工作方式如下:
HTTP://example.com:8080/apex/f?p=[APP]:[Page]:[Session] etc
其中[APP]、[Page]、[Session]都是对应的数字
开发环境 url 实际上是:
这是默认设置,所以如果我尝试http://example.com:8080/apex/它默认为http://example.com:8080/apex/f?p=4550并带您进入登录页面
应用程序编号之后的所有内容都不会改变,所以我想用 /dev/ http://example.com:8080/apex/f?p=4550:1 -> http://example.com/dev/替换:1
一旦我了解了它的工作原理,我计划设置三个 proxy_pass
example.com/dev -> http://example.com:8080/apex/f?p=4550
example.com/desktop -> http://example.com:8080/apex/f?p=1001
example.com/mobile -> http://example.com:8080/apex/f?p=201
唯一改变的是应用程序编号。
重写对所有三个都很好,但我不希望重写在 URL 中可见
以下是重写:
location ~ /dev {
rewrite ^/dev(.*) http://smallblockpro.com:8080/apex$1 last;
}
location ~ /desktop/ {
rewrite ^/desktop/(.*) http://smallblockpro.com:8080/apex/f?p=1001:$1 last;
}
location ~ /desktop {
rewrite ^/desktop(.*) http://smallblockpro.com:8080/apex/f?p=1001:$1 last;
}
location ~ /mobile/ {
rewrite ^/mobile/(.*) http://smallblockpro.com:8080/apex/f?p=201:$1 last;
}
location ~ /mobile {
rewrite ^/mobile(.*) http://smallblockpro.com:8080/apex/f?p=201:$1 last;
}