Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure nginx for Amazon ec2

I saw example configurations of nginx, most of them use example.com as a server_name and uwsgi_pass similar to unix:/var/www/run/blog.sock; or in combination with ip/port address. but what should I use in case of amazon ec2 instance, since it has long public name, ip is private and if I restart my instance it gets different public name and ip. I need shutdown instances sometime. I want to configure it for using uwsgi+django, but I am totally beginner in web area and servers.

like image 898
user1318496 Avatar asked Sep 04 '25 17:09

user1318496


1 Answers

The server_name directive is useful in cases where you want to host different sites on the same server, and handling them differently depending on the "Host" header field (ex: mysite1.com => a PHP website, mysite2.com => a django website,...) It's actually a virtual server (see also [the server directive])1.

From this article :

[...] nginx tests only the request’s header field “Host” [against the server_name directive] to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port.

If I understood, you don't want that. So you can use the underscore character (in the Miscellaneous Names section).

When I don't need to handle specific domains, I generally use "localhost". To be honest I couldn't find any explanation on what it does. I just found examples with this value, and it seems to work exactly as the underscore character.

So I'd go with

server_name _;

or

server_name localhost;
like image 138
Julien Avatar answered Sep 07 '25 21:09

Julien