user5619184 February 2016

Nginx server name difference

If the server ip is 10.0.0.0, 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 10.0.0.0 example.com;

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

Answers


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 {

    listen 10.0.0.0:80;

    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

Search




Leave an answer