Proxy_pass忽略端口 [英] Proxy_pass ignoring port
问题描述
我有一台运行NGINX的CentOS服务器,可以监听80,而DB则在8080上为一个应用程序提供服务器.我希望能够输入
I have a CentOS server running NGINX listening to 80 and a DB servering an app on 8080. I want to be able to Type
并让其实际访问
http://example.com:8080/apex/abc 或 http://localhost:8080/apex/abc
我已经使用了此位置配置
I have used this location configuration
location /dev {
proxy_pass http://example.com:8080/apex;
}
但是,当我尝试使用时,显示的网址是
However when I try it out the url displayed is
找不到页面,日志显示:
the page is not found and the log says:
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"
看起来好像发生了两件奇怪的事情
Looks like two strange things are happening
1)尽管使用了proxy_pass,端口80仍未使用8080
1) Port 80 not 8080 is being used despite the proxy_pass
2)为什么顶点两次"/apex/apex/"
2) why is apex twice "/apex/apex/"
请帮助:)
从配置文件添加整个服务器块:
Adding entire Server block from config file:
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的工作方式如下:
The app is Oracle Application Express (APEX) it listens on port 8080. The URL works as follows:
HTTP://example.com:8080/apex/f?p=[APP]:[Page]:[Session] etc
[APP],[Page]和[Session]都是对应的数字
Where [APP],[Page] and [Session] are all corrisponding numbers
开发环境网址实际上是:
The development environment url is actualy:
这是默认设置,因此如果我尝试 http://example.com:8080/apex/默认为 http://example.com:8080/apex/f?p = 4550 并带您进入登录页面
This is the default so if I try http://example.com:8080/apex/ it defaults to http://example.com:8080/apex/f?p=4550 and takes you to the login page
应用编号后的所有内容都不会更改,因此我想用/dev/ http://example.com:8080/apex/f?p=4550:1 ->
Everything after the app number never changes so that is what I want to replaced by /dev/ http://example.com:8080/apex/f?p=4550:1 -> http://example.com/dev/:1
一旦我确定其工作原理,我计划设置三个proxy_pass
Once I have leant how this works, I plan to setup three proxy_pass's
example.com/dev-> http://example.com:8080/apex/f?p=4550
example.com/dev -> http://example.com:8080/apex/f?p=4550
example.com/desktop-> http://example.com:8080/apex/f?p=1001
example.com/desktop -> http://example.com:8080/apex/f?p=1001
example.com/mobile-> http://example.com:8080/apex/f?p=201
example.com/mobile -> http://example.com:8080/apex/f?p=201
唯一更改的是应用程序编号.
Where the only thing that changes is the app number.
这三个文件的重写都可以正常工作,但我不希望该重写在URL中可见
Rewrites are working fine for all three but I don't want the rewrite to be visible in the 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;
}
推荐答案
这是我在ORDS/SDW(sqldev-web)开发服务器上使用的复制粘贴.
Here's the copy-paste from what I'm using on our ORDS / SDW ( sqldev-web ) development server.
这是在房屋的REST一侧使用ORDS的基本示例.
Here's a basic example with ORDS for the REST side of the house.
访问权限是:
https://xyz.oraclecorp.com/sdw/klrice/metadata-catalog/
然后将其代理为:
https://xyz.oraclecorp.com:8083/ords/klrice/metadata-catalog/
使用此配置.除了不重写为绝对URI之外,因为这样做将进行完整的浏览器重定向,而不仅仅是重写代理通过的URL.
With this config. Beside not to rewrite to an absolute URI as that will do a full browser redirect vs just rewriting the url for the proxy pass.
location /sdw/ {
rewrite /sdw/(.*) /ords/$1 break;
proxy_pass https://xyz.oraclecorp.com:8083/ords/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
您将要面对的问题是
rewrite ^/desktop/(.*) http://smallblockpro.com:8080/apex/f?p=1001:$1 last;
APEX将以.../apex/XYZ
的身份查看和写入链接/重定向/包含(javascript/css/...),这将影响nginx服务器,并且不知道如何处理/apex/
APEX will see and write links/redirects/includes ( javascript/css/...) as the .../apex/XYZ
which will hit the nginx server and that will not know what to do with a /apex/
这是基于我上面的设置的一个示例.请注意,我对/sdw/的请求变成了重定向到/ords/
Here's an example of that based on my above setup. Notice my request to /sdw/ turns into a Location redirect to /ords/
wget -S https://xyz.oraclecorp.com/sdw/
--2018-06-21 17:10:28-- https://xyz.oraclecorp.com/sdw/
Resolving xyz.oraclecorp.com... 123.456.789.123
Connecting to xyz.oraclecorp.com|123.456.789.123|:443... connected.
HTTP request sent, awaiting response...
HTTP/1.1 302 Found
Server: nginx/1.12.1
Location: https://xyz.oraclecorp.com/ords/f?p=4550:1:375440000433:::::
Location: https://xyz.oraclecorp.com/ords/f?p=4550:1:375440000433::::: [following]
因此,最简单的方法是将ords部署(/apex/)与重写/重定向相匹配,并使用proxy pass来内部化:8080内容.所以
So the easiest thing to do is match up the ords deployment ( /apex/ ) to what the rewrite/redirects are and use proxy pass to internalize the :8080 stuff. So
location ~ /desktop/ {
rewrite ^/desktop/(.*) http://smallblockpro.com/apex/f?p=1001:$1 last;
}
location ~ /apex/ {
proxy_pass http://smallblockpro.com:8080/apex/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
此选项将使您的用户拥有一个不错的/desktop/入口点,但随后会为应用程序本身重定向/apex/.
This option will let your users have a nice entry point of /desktop/ but then that redirect the /apex/ for the app itself.
ORDS url-mappings.xml中还有一个选项可以保留/desktop/,也可以像这样将其添加到ords的映射中,以便知道/desktop/.然后,nginx可以对每个条目URL进行相同的代理传递.
There is another option with ORDS url-mappings.xml to keep the /desktop/ also which would be something like this to add in mappings to ords so it knows the /desktop/. Then the nginx could do the same proxy pass for each of the entry urls.
url-mapping.xml文件内容
url-mapping.xml file contents
<pool-config xmlns="http://xmlns.oracle.com/apex/pool-config">
<pool name="mypool" base-path="/desktop" />
</pool-config>
然后在nginx中
location ~ /desktop/ {
proxy_pass http://smallblockpro.com:8080/desktop/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
这篇关于Proxy_pass忽略端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!