!长时间不使用,总忘记怎么配置。还是记录一下吧!!!🚀🚀🚀
# 默认会到/etc/nginx/conf.d/目录下寻找 *.conf 文件,所以在该目录下直接新建一个.conf文件即可!
/etc/nginx/conf.d/tex.conf
server {
listen 5000; #监听端口可以随意指定,有时候服务器80端口会不好用
server_name xxx.161.xxx.251; #公网IP,服务器外网ip
index index.html index.htm;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-
Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
proxy_pass http://127.0.0.1:8987/; #访问目标的地址 # 这里我是访问我的Flask框架
}
location /convert {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
proxy_pass http://127.0.0.1:3000/convert; #当访问/convert路由时,可以访问目的标的地址
}
}
这样访问 公网ip:5000 就可以访问到其他目标地址了,解决跨域问题!