在nginx

时间:2017-09-01 18:19:52

标签: http nginx https proxy http-proxy

我的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/

如果架构或端口不同,那对我来说并不重要。

有什么建议吗?

更新

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

1 个答案:

答案 0 :(得分:1)

以下更改

listen 443 ssl;
server_name api.local.awesome.com;

listen 443 ssl;
listen 80;
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/

访问它