捕获特定的服务器上的nginx
我nginx的文件看起来像:捕获特定的服务器上的nginx
server {
listen 443 ssl;
server_name local.awesome.com;
ssl_certificate /opt/certs/local.awesome.com.crt;
ssl_certificate_key /opt/certs/local.awesome.com.key;
location/{
root /var/www/awesome.com/public_html/;
index index.html;
}
}
server {
listen 443 ssl;
server_name api.local.awesome.com;
ssl_certificate /opt/certs/local.awesome.com.crt;
ssl_certificate_key /opt/certs/local.awesome.com.key;
root /var/www/api.awesome.com/public_html/;
# Known locations for static resources
location /resources/ {
}
# Process all other requests via JS in index.html
location/{
rewrite .* /index.html;
break;
}
location /api {
rewrite "^/api/(.*)$" /$1 break;
proxy_pass http://api:8001;
}
}
如果我查询类似于:
GET https://api.local.awesome.com/api/
这工作得很好。
我决定把这个全局访问共享一些数据。
我想请求:
GET https://192.168.1.3:443/api/
但是,这是行不通的。它返回HTTP/1.1 404 Not Found
。
该请求将返回403 Forbidden
:
GET https://192.168.1.3:443/
看起来一切都与授权,在这里,但我希望以前的请求应该返回的东西从Not Found
不同。
这里有什么问题以及如何更换:
GET https://api.local.awesome.com/api/
与
GET http://192.168.1.3:443/api/
如果架构或端口不同的是不适合我的关键。
有什么建议吗?
UPDATE:
curl -v http://192.168.1.3/api/
* Trying 192.168.1.3...
* TCP_NODELAY set
* Connected to 192.168.1.3 (192.168.1.3) port 80 (#0)
> GET /api/ HTTP/1.1
> Host: 192.168.1.3
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.13.3
< Date: Fri, 01 Sep 2017 18:55:05 GMT
< Content-Type: text/html
< Content-Length: 185
< Connection: keep-alive
< Location: https://192.168.1.3/api/
<
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.13.3</center>
</body>
</html>
* Connection #0 to host 192.168.1.3 left intact
更改下面
listen 443 ssl;
server_name api.local.awesome.com;
到
或
listen 443 ssl;
listen 80;
server_name api.local.awesome.com 192.168.1.3;
这将允许您使用http://192.168.1.3/api/
它返回'HTTP/1.1 301永久移动'。我已经变成你的第二个建议。 – smart
这是您发布的完整配置,或者你有更多的东西也?也有什么'卷曲-v HTTP的输出:// 192.168.1.3/API /' –
我已经更新了卷曲的响应的问题。这是一个配置文件中的所有的configs,但它看起来像80端口可以通过nginx的容器中使用:'泊坞窗PS | grep的nginx的 2258ae964073 nginx的:高山 “nginx的-g“守护......” 11小时前最多8分钟0.0.0.0:80->80/tcp,0.0.0.0:443-> 443/tcp' – smart
您希望两者同时工作还是仅工作一个? –
这将足以只有一个工作的别名。 – smart