需求:使用一台服务器的80端口部署api+web+接收微信 接口配置信息 的GET请求

前端开发使用JS-SDK来调用腾讯地图的功能并在公众号正常使用.
开发时只有一台腾讯云的服务器,需要同时配置微信公众号的 接口配置信息, JS接口安全域名.[见微信公众号配置]

nginx配置[80端口的server]:

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    #root /var/www/html;

    # Add index.php to the list if you are using PHP
    #index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # 此处配置是接收微信公众号 接口配置信息 的请求,微信服务器需要发送HTTP GET请求给当前server的80端口,只能是80端口.
        # 后端使用的flask+uwsgi,此处配置保证转发了HTTP请求,对应后端的flask api可用.
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:5000; 
    }
    
    #location /v1/api/ {
    #    此处配置的是项目的api接口服务,此处配置和上面的location / 合一起了.
    #    include uwsgi_params;
    #    uwsgi_pass 127.0.0.1:5000;
    #}    
    
    # 此处的需求:
    # 访问http://IP/sites/index.html  能正常访问index.html页面,同时保证api可用.
    
    location /sites {
        alias /root/sites;  # web项目的目录
        index index.html;   # index.html
        try_files $uri @rewriteweb;
    }
    location @rewriteweb {
        rewrite ^/sites/(.*)$ /sites/index.html break;  # 注意此处的break
    }



}




ceephoen
40 声望6 粉丝

coding~~~