【发布时间】:2018-11-23 16:26:36
【问题描述】:
我有一个运行 NGINX 的 CentOS 服务器来监听 80,还有一个 DB 为 8080 上的应用程序提供服务器服务。我希望能够输入
并让它实际访问
http://example.com:8080/apex/abc 或 http://localhost:8080/apex/abc
我用过这个位置配置
location /dev {
proxy_pass http://example.com:8080/apex;
}
但是,当我尝试时,显示的网址是
找不到页面,日志显示:
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;
}
【问题讨论】:
-
使用听 80; server_name example.com;location /dev {proxy_pass example.com:8080/apec;}
-
谢谢,但没有修复它我没有 server_name 部分,它仍然删除 :8080 并添加一个额外的 apex/即 example.com/apex/apex 我将放置整个服务器阻止以防其他地方出现问题。
-
嗯,这令人失望,花了几个小时,尝试了所有建议,没有得到解决,但仍然失去了赏金。然后看起来每个尝试过的人都对我的问题投了反对票,没有给出任何理由。甚至有人用它来尝试工作。将赏金分配给克里斯,因为他尽最大努力提供帮助。
-
@AndrewT,当您没有规范时,您无法解决规范的问题。您的问题需要 nginx(编写配置)和 Oracle ApEx(了解其工作原理并提出 nginx 规范)的高级知识。您无法获得解决方案并被否决,这并不奇怪,TBH,因为您要求的是 nginx 配置,但无法在伪代码中解释此类配置必须考虑的操作。
-
@cnst 如果我有上述知识,我不会问这个问题。我正在尝试做的事情我认为使用 NGINX 或 apache 将 url 映射到用于数百万互联网应用程序的 Apex 并不罕见。我希望以前做过这件事的人可以提供帮助,我没想到有人会根据我的设计规范来构建东西。我做了很多更新,并每天多次尝试所有建议来尽我所能,因为是的,我自己没有知识去做。当您解决部分问题在应用程序端时,我什至赞成您的评论。我尽力了
标签: nginx url-rewriting oracle-apex nginx-location ngx-http-rewrite-module