Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

nginx配置 访问https接口

数据接口是在网上抓取的https接口,项目部署时,请问nginx该如何配置?
目前Status Code: 200 OK,但页面不显示数据

        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            root /root/www/;
            index index.html index.htm;
        }
        
        location /ajax/ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass https://****.com;

            proxy_redirect off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
        }
        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

假设你的网上爬取数据接口地址为https://www.data.com

项目

那么你在项目中只需要访问一个特定的localtion,比如项目直接ajaxurl请求/data,其实访问的就是http://localhost:port/data

nginx

你只需要在你对应的serve下配置代理即可,你需要代理/data

location ^~/data/ {
    proxy_pass https://www.data.com/;
    proxy_set_header HOST $host;
    proxy_buffers 256 4k;
    proxy_max_temp_file_size 0k;
    proxy_connect_timeout 30;
    proxy_send_timeout 60;
    proxy_read_timeout 60;
    proxy_next_upstream error timeout invalid_header http_502;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...