我已经更改了 /home/dokku// 中的默认 nginx.conf
对于这个:
upstream $APP-domains { server $INTERNAL_IP:$PORT; }
server {
listen [::]:80;
listen 80;
server_name $EXTERNAL_IP;
location / {
proxy_pass http://$APP-domains;
proxy_http_version 1.1;
proxy_set_header Upgrade $$http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Host $$host;
proxy_set_header X-Forwarded-Proto $$scheme;
proxy_set_header X-Forwarded-For $$remote_addr;
proxy_set_header X-Forwarded-Port $$server_port;
proxy_set_header X-Request-Start $$msec;
proxy_cache_bypass $$http_upgrade;
}
}
其中$APP、$PORT、$INTERNAL_IP、$EXTERNAL_IP应根据部署的 dokku 应用程序而更改。
$PORT = /home/dokku //PORT
$INTERNAL_IP = /home/dokku//IP
$APP = app_name
$EXTERNAL_IP = 您的公共 IP
更改应用程序位置内的 nginx.conf 后,您应该重新启动 NGINX(sudo service nginx restart)
这是一个使用fabric处理这个过程的python gist:
@task
def config_vhost(ip, app):
"""Use the nginx template to redirect app to port 80"""
port = run('cat /home/dokku/{}/PORT'.format(app))
internal_ip = run('cat /home/dokku/{}/IP'.format(app))
values = {'EXTERNAL_IP': ip, 'INTERNAL_IP': internal_ip, 'PORT': port, 'APP': app}
nginx = open(NGINX_TEMPLATE, 'r').read()
nginx_template = string.Template(nginx)
nginx_conf = nginx_template.substitute(values)
sudo("echo '{}' > /home/dokku/{}/nginx.conf".format(nginx_conf, app))
sudo("service nginx restart")