Home Ask Login Register

Developers Planet

Your answer is one click away!

user5619184 February 2016

Nginx server name difference

If the server ip is, but I'm mapping it to make it to have www.example.com, is the below config the correct way to do it?

server {

    listen 80;

    server_name example.com;

    access_log /var/log/nginx/example.log;


Mathias R. Jessen February 2016

No, if you want to restrict a server to a single interface address, it needs to go with the listen directive:

server {


    server_name example.com;

    access_log /var/log/nginx/example.log;


r00k February 2016

above answer, or you can just setup a basic server block

server {
listen 80;
listen [::]:80;

root /var/www/folderName/htdocs; // where you have your project folder and public directory
index index.html index.htm;  // add index.php here if using php files

server_name test.com www.test.com;   // desired url goes here

location / {
    try_files $uri $uri/ =404;


the tutorials from digital ocean are pretty nice - https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts

Post Status

Asked in February 2016
Viewed 1,283 times
Voted 8
Answered 2 times


Leave an answer

Quote of the day: live life