How to access WordPress Website by IP Address


#1

I’ve seen four (or more) different support requests about this issue and have tried all the options suggested, and yet still cannot access a new WordPress Website, using only the IP Address as the URL.

I can access Admin Tools using http://ip-address:22222 just fine. However, even after updating /etc/hosts with:

IP-Address Domain-Name

…reloading nginx with:

nginx -t && service nginx reload

…and navigating to IP Address, the standard “Welcome to nginx” HTML page is displayed.

I made additional attempts at resolving this issue by changing the following line:

root /var/www/html;

…in:

/etc/nginx/sites-enabled/default

…to:

root /var/www/domain-name;

…and:

root /var/www/domain-name/htdocs;

…all of which only result in a 403 Error.

Accessing a WordPress Website by IP Address, on EE, can’t be that difficult, can it?


#2

@bamajr

to access your site with the ip address, you need to put your ip address as server_name in your site config.

lets say

ee site edit example.com

Edit following line

server_name example.com www.example.com 10.0.0.1;


#3

@harshadyeola this method causes a re-direct to occur, redirecting to the live website. I’ve included the contents of this file, as I have it configured, currently, below:

# Uncomment the following line for domain mapping
# listen 80 default_server;

server_name 23.251.152.195;

# Uncomment the following line for domain mapping
#server_name_in_redirect off;

access_log /var/log/nginx/example.com.access.log rt_cache;
error_log /var/log/nginx/example.com.error.log;

root /var/www/example.com/htdocs;

index index.php index.html index.htm;

include common/wpfc.conf;
include common/wpsubdir.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/example.com/conf/nginx/*.conf;

However, I’ve also tried switching:

server_name 23.251.152.195;

…to:

server_name example.com 23.251.152.195;

…and:

server_name example.com *.example.com 23.251.152.195;

All of these redirect to the LIVE website found at example.com

To clarify, I’m building a new website for example.com and example.com is already a LIVE site, in a production environment. The new example.com website will be found at 23.251.152.195 and I want to be able to access the installation of WordPress, found there, by navigating to http://23.251.152.195/ directly. However, as I’ve already indicated above, none of the previously provided solutions, found in other support posts work, and the most recent solution you provided (above) causes http://23.251.152.195/ to re-direct to the LIVE site found at http://example.com/

What am I missing?


#4

Hello, To me it has worked but the IP addresses at http://dominio.com/wp-signup.php?new=104.40.204.156 instead of the home page and domino.com send me to the homepage. !?


#5

The only way I’ve been able to find to access a WordPress website by IP Address, when installed with EasyEngine, is to install it using the IP Addresses, as shown below:

sudo ee site create the.ip.add.ress --wpsubdir --wpfc

…and then it is only available by IP Address and not a domain. None of the suggestions to access a WordPress website by IP Address have worked.


#6

380 days old and still no resolution…

Why is it that such a common practice of using the IP Address to access a website, until one is ready to go live, is so difficult to do in EE/NGINX?

As indicated above, I have tried the following:

server_name 23.251.152.195;

…and…

server_name example.com 23.251.152.195;

…and…

server_name example.com *.example.com 23.251.152.195;

…and…

server_name example.com www.example.com *.example.com 23.251.152.195;

All of the above attempts to access the new EE site, located on 23.251.152.195 are simply redirected to the LIVE website found at example.com


#7

The easiest way, IMHO, is editing your hosts file (your computer, not at the server).

If you use MacOS: sudo vim /private/etc/hosts

Linux: sudo vim /etc/hosts

Windows: Open c:\windows\system32\drivers\etc\hosts

Add one line to this file:

1.2.3.4 example.com www.example.com

Save the file and access your site. You’ll bypass any DNS resolution and access your site before actually publishing it.


#8

Thank you @janiosarmento

Yes, this is a very effective way to bypass any DNS resolution and I’ve used it a number of times. Most times this works well enough, though it is quite annoying if you need to switch back and forth between DEV and LIVE sites.

I’m specifically interested in an EE supported method, b/c of this annoyance.


#9

As far as I know, there is nothing better then hosts file for this kind of need.


#10

The local hosts file is definitely effective. Just baffled by how this request doesn’t have an easy fix. Have been able to do this with Apache-based WordPress deployments, say with something like Virtualmin, for years.


#11

This php-snippet

remove_action('template_redirect', 'redirect_canonical');

disables “WordPress’-Redirect-behaviour”, with it you can access it by IP-Address.


#12

This does work, mostly…

If I go to https://ip.address/ I’m able to see my WordPress website. GREAT!

@ingobaab Thank you for posting this. Adding this remove_action snippet to the functions.php file, from the command line, is a cinch and a very easy solution.

However, if I go to http://ip.address/ I get the same old “Welcome to nginx” screen:


#13

I think this depends on how your nginx is configured. Does it serve on both HTTP and on HTTPS (ports80/443)? Or does it a redirect from http:// to https://? (301)? I have no experience in “default server - option for HTTPS”, but here is a discussion about it:

–good luck : )


#14

Thanks @ingobaab , I’ll check out the discussion you linked.

I’ll have to look into this a little bit more. I’m currently using the default configuration set by using the:

sudo ee site update example.com --letsencrypt

…command.


#15

Check this locations:

/etc/nginx/conf.d/*

and

/var/www/[sitename]/conf/nginx/*

and of course:

/etc/nginx/sites-enabled/*

to see what is configured…


#16

Yes, thank you.

The force-ssl-example.com.conf file is set up like so:

server { listen 80; server_name www.example.com example.com; return 301 https://example.com$request_uri; }

----->

The /var/www/example.com/conf/nginx/ssl.conf file is set up like so:

listen 443 ssl http2; ssl on; ssl_certificate /etc/letsencrypt/live/bamajr.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/bamajr.com/privkey.pem;

----->

The /etc/nginx/sites-enabled/example.com file is configured like so:

`server {

# Uncomment the following line for domain mapping
# listen 80 default_server;

server_name example.com *.example.com;

# Uncomment the following line for domain mapping
#server_name_in_redirect off;

access_log /var/log/nginx/example.com.access.log rt_cache_redis;
error_log /var/log/nginx/example.com.error.log;


root /var/www/example.com/htdocs;



index index.php index.html index.htm;


include common/redis-php7.conf;
include common/wpsubdir.conf;
include common/wpcommon-php7.conf;
include common/locations-php7.conf;
include /var/www/example.com/conf/nginx/*.conf;

}`

----->

Do you notice anything odd about this configuration?


#17