nginx 二级目录

26次阅读

共计 1214 个字符,预计需要花费 4 分钟才能阅读完成。

需求: 使用一台服务器的 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
}

}

正文完
 0