【发布时间】:2016-05-07 07:02:59
【问题描述】:
我是第一次使用 Nginx。
- 我有两台服务器。服务器一(ip:1.2.3.4) 服务器二(ip: 5.6.7.8)
- 我已经在服务器 1 上安装了 nginx,在服务器 2 上安装了 Tomcat。
-
我已成功配置 tomcat 以在不同的端口上运行。我的 tomcat 正在以下端口上运行。
5.6.7.8:8080
5.6.7.8:8081
5.6.7.8:8082 我还在tomcat(每个实例)上部署了我的war文件。
我的nginx配置如下
在 /etc/nginx/conf.d 中创建了一个 default.conf
-
根据以下链接Nginx Configuration对文件进行修改
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; # Make site accessible from http://localhost/ server_name 1.2.3.4; location / { proxy_pass http://www.example.com; # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rule } location /user/{ proxy_pass http://5.6.7.8:8080$uri; # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rule }}
我在SERVER TWO上部署的War文件名是Example。
其中包含一个 api/user/login?param1=xyz&param2=abc&param3=mno- 当我点击 ip 1.2.3.4 时,它会转到 root(/)。我得到了预期的结果。我得到了 example.com 页面。
- 但是当我点击 1.2.3.4/user 时,我得到 404 not found。 我期待我的 api 会被调用并且我会得到结果。
- 如果我点击
5.6.7.8:8080/Example//user/login?param1=xyz¶m2=abc¶m3=mno,检查我的 api 是否正常工作。我得到了我期望的正确的 json 结果。 - 当我点击 1.2.3.4/user 时,我期待同样的结果。但我得到 404。
当我点击 1.2.3.4/user 时,我必须更改哪些内容才能获得结果
谢谢
【问题讨论】: