Ubuntu 上配置 Nginx 另一种方法,cd 到 /etc/nginx/conf.d 文件夹,新建 xxx.conf 文件(xxx 可以是项目名,只要是 .conf 文件即可),写入以下内容:
upstream flask {
server 127.0.0.1:5000; # Gunicorn 配置的ip和端口
}
server {
listen 80; # 监听80端口
server_name localhost; # 本机
location / {
# 请求转发到gunicorn服务器
proxy_pass http://flask;
# 设置请求头,并将头信息传递给服务器端
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
需要监听 https 请求时,写入以下内容:
upstream health {
server 127.0.0.1:5000; # Gunicorn 配置的 ip 和端口
}
server {
listen 9000 ssl; # 443 端口被占用,这里监听 9000 端口
server_name health; # 这里填入 上面的 upstream 对应的 health 也可以(localhost 也可以)
ssl_certificate cert/2979212_www.zolarobot.com.pem; # 证书公钥,这里在nginx.conf所在文件夹下面的cert文件夹里面
ssl_certificate_key cert/2979212_www.zolarobot.com.key; # 证书私钥
location / {
proxy_pass http://health;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
需要更多教程,微信扫码即可
别忘了扫码领资料哦【高清Java学习路线图】
和【全套学习视频及配套资料】



