Adam Michael Wood
Adam Michael Wood

Reputation: 1788

All requests to same directory, regardless of domain - NGINX

(I think my question has a non-WP-specific solution.)

Domains that point at my server's IP address don't get sent to my WordPress site unless they are defined in the config file or the domain is defined in /sites-enabled

So, if I just set the A-record of some random example.com domain to my IP, I get a "Welcome to nginx on Debian!" message.

But I need it to go directly to the WordPress directory.

And I need it to happen anytime anyone sets up a domain to point at the IP address. That is --- I need to set up the config so all requests go to the WordPress directory.

EDIT:

I have tried to set the default directory to /var/www/wordpress --- but that didn't seem to work.

Upvotes: 0

Views: 97

Answers (2)

Adam Michael Wood
Adam Michael Wood

Reputation: 1788

The solution was simple:

server {
listen 80 default_server;
server_name myprimarydomain.com *.myprimarydomain.com;
server_name_in_redirect off;
root /var/www/wordpress;
.
.
.

If you followed the Nginx/Multisite guide from WPMU --- you also have to remove the default file in the sites-available directory. It is being included by a line in the confd file, and it contains a conflicting default_server line.

Upvotes: 0

steppefox
steppefox

Reputation: 1844

You can use regex in nginx/conf.d/ config, to catch domains:

server {
    listen 80;
    set $location_root "/var/www/";

    server_name ~^(?<somedomain>[\w-\.]+\.com)$;
    root $location_root/$somedomain;
    include conf.d/wpconf;
}

If you have domains not only in *.com area, just fix regex. For example, for domain site.com, this regex will go to /var/www/site.com directory.

Note: including conf.d/wpconf is not necessary, because i store in that file specific options for WPsites.

Upvotes: 1

Related Questions