Linode Forum
https://forum.linode.com/

Accessing site via IP address with nginx configuration
https://forum.linode.com/viewtopic.php?f=19&t=10682
Page 1 of 1

Author:  suncloud [ Mon Dec 09, 2013 8:16 pm ]
Post subject:  Accessing site via IP address with nginx configuration

I have several websites on my linode LEMP stack (using nginx instead of apache). Each site lives in a separate folder /srv/www/sitename.com, where sitename is the name of the respective site.

I'm trying to migrate one site from it's previous host but I dont want to change the DNS records until the site is setup. However, I can't figure out how to access the site without it's domain name. I've tried IP-address/sitename.com but that just redirects me to my default_server.

Each domain has a configuration file in /etc/nginx/sites-available that looks something like this (below). What should I add to the configuration so that I can access the site with the ip address instead the sitename?:

server {
listen 80;
server_name www.sitename.com sitename.com;
access_log /srv/www/sitename.com/logs/access.log;
error_log /srv/www/sitename.com/logs/error.log;
root /srv/www/sitename.com/public_html;
index index.php;

rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/sitename.com/public_html
}

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}

Any help is appreciated! Thanks.

Author:  caker [ Mon Dec 09, 2013 8:20 pm ]
Post subject:  Re: Accessing site via IP address with nginx configuration

Edit your LOCAL computer's /etc/hosts file and add an entry for the IP and domain name you're trying to test. Your LOCAL computer uses this file FIRST when trying to resolve hostnames. This allows you to redirect your LOCAL computer to a different IP for a given hostname, without mucking with global DNS or server side changes.

Good luck!
-Chris

Author:  jgjh151 [ Tue Dec 10, 2013 2:44 pm ]
Post subject:  Re: Accessing site via IP address with nginx configuration

I have /etc/nginx/sites-available/default pointing to srv/www/default/public_html, it loads a plain html file when the IP is placed in browser. To test a new site before DNS, I change root to "root /srv/www/sitename.com/public_html;" to point the IP to the site I just migrated. When all is tested, I put default back and place /etc/nginx/sites-available/sitename.com so it's ready to go.

Code:
server {
listen 80;
server_name 123.45.67 my.fqdn.com;
access_log /srv/www/default/logs/access.log;
error_log /srv/www/default/logs/error.log;
root /srv/www/default/public_html;
...

Code:
server {
listen 80;
server_name 123.45.67 my.fqdn.com;
access_log /srv/www/default/logs/access.log;
error_log /srv/www/default/logs/error.log;
root /srv/www/sitename.com/public_html;
...

Page 1 of 1 All times are UTC-04:00
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/