简体   繁体   中英

Update server_name in nginx.conf programmatically

I have a trading bot built with flask+gunicorn+nginx deployed on AWS EC2 which runs for 8 hours a day. Everytime I start the instance, the public IP changes which I need to update the server_name in nginx.conf. Is there a way to update this daily with the help of a script or service? My conf file looks like this:

server{
                listen 80;
                server_name "public ip I need to change everyday";

                location / {
                            .
                            .}
        }

Thanks.

Since your Nginx configuration has only one server block, make that block the default block. It will capture all requests regardless of the server IP. Therefore, you don't need to specify an IP for the server_name directive.

server {
    listen       80  default_server;
    server_name  _;
    
    # Please put other settings below.
    #...
}

For more information, visit the Server names document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM