nginx 二級目錄

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

前端開發使用JS-SDK來調用騰訊地圖的功能並在公衆號正常使用.
開發時只有一臺騰訊雲的服務器,須要同時配置微信公衆號的 接口配置信息, JS接口安全域名.[見微信公衆號配置]php

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
    }



}
相關文章
相關標籤/搜索