• Hello, I have looked high and low trying to solve this issue. I am new to nginx and multisite so this probably has an easy solution.

    I can create a new site on the backend, but when I visit that new site (subdomain.example.com) it redirects to the main site.

    I have a wildcard subdomain pointing my main site (example.com) it looks just like this image: https://namecheap.simplekb.com//SiteContents/2-7C22D5236A4543EB827F3BD8936E153E/media/wildcard%20subdomain.jpg

    Doing things the Debian way, I have my site config in /sites-available
    It looks like:

    server {
    server_name *.example.com;
    #rewrite ^ https://www.example.com$uri permanent;

    server_name *.otherexample.net;
    server_name *.anotherexample.com;

    root /var/www/virtenu;
    index index.html index.htm index.php;

    location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html
    try_files $uri $uri/ /index.html;
    }

    location /doc/ {
    alias /usr/share/doc;
    autoindex on;
    allow 127.0.0.1;
    deny all;
    }

    include template.conf;
    include wordpress.conf;

    }

    As you can see, I have the 2 domains I eventually want to map pointing to the same location as the main.

    The template.conf takes care of the php and a few security related things:

    # pass php requests to php-fpm
    location ~ \.php$ {

    # It’s better to connect php script via socket as on some servers number of concurent TCP connections can be limited
    #fastcgi_pass unix:/var/run/php-fpm/phpsock.sock;

    try_files $uri =404;
    #fastcgi_pass 127.0.0.1:9000;
    fastcgi_pass unix:/var/run/php5-fpm/phpsock.sock;
    fastcgi_index index.php;
    fastcgi_intercept_errors on; # display errors use only for testing
    #Include params from /etc/nginx/fastcgi_param
    include fastcgi_params;
    fastcgi_ignore_client_abort on;
    }

    # Global restrictions configuration file.
    # Designed to be included in any server {} block.</p>
    location = /favicon.ico {
    log_not_found off;
    access_log off;
    }

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

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
    }

    # Deny access to any files with a .php extension in the uploads directory
    location ~* ^/wp-content/uploads/.*.php$ {
    deny all;
    access_log off;
    log_not_found off;
    }

    And the wordpress.conf is copied from somewhere, I have tried different ones in hopes to solve the issue to no avail. This is what it currently is:

    # WordPress multisite subdirectory rules.
    # Designed to be included in any server {} block.

    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    # Directives to send expires headers and turn off 404 error logging.
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 24h;
    log_not_found off;
    }

    # Pass uploaded files to wp-includes/ms-files.php.
    rewrite /files/$ /index.php last;

    # For multisite: Use a caching plugin that creates symlinks to the correct subdirectory structure to get some performance gains.
    set $cachetest “$document_root/wp-content/cache/ms-filemap/${host}${uri}”;
    if ($uri ~ /$) {
    set $cachetest “”;
    }
    if (-f $cachetest) {
    # Rewrites the URI and stops rewrite processing so it doesn’t start over and attempt to pass it to the next rule.
    rewrite ^ /wp-content/cache/ms-filemap/${host}${uri} break;
    }

    if ($uri !~ wp-content/plugins) {
    rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
    }

    # Uncomment one of the lines below for the appropriate caching plugin (if used).
    #include global/wordpress-ms-subdir-wp-super-cache.conf;
    #include global/wordpress-ms-subdir-w3-total-cache.conf;

    # Rewrite multisite ‘…/wp-.*’ and ‘…/*.php’.
    if (!-e $request_filename) {
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
    }

    # unless the request is for a valid file, send to bootstrap
    if (!-e $request_filename)
    {
    rewrite ^(.+)$ /index.php?q=$1 last;
    }

    Just in case, here is my nginx.conf as well:

    user www-data;
    worker_processes 4; # Set accoring to number of processor cores
    pid /var/run/nginx.pid;
    error_log /var/log/nginx/error.log;
    events {
    worker_connections 1024;
    # multi_accept on;
    }

    http {
    ##
    # Basic Settings
    ##
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 30;

    types_hash_max_size 2048;
    client_max_body_size 13m;
    server_tokens off; # hide server info on errors
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    ##
    # Gzip Settings
    ##
    gzip on;
    gzip_disable “MSIE [1-6].(?!.*SV1)”;
    gzip_min_length 1100;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    }

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter en3r0

    (@en3r0)

    I have simplified things, this is now my virtualhost file for exmaple.com

    server {
    server_name example.com *.example.com;
    #rewrite ^ https://www.example.com$uri permanent;

    server_name *.otherexample.net;
    server_name *.anotherexample.com;

    root /var/www/example;
    index index.html index.htm index.php;

    location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html
    try_files $uri $uri/ /index.php?$args;

    rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
    }

    location ~* ^.+\.(js|css|png|jpg|jpeg|gif|ico)$ {
    rewrite ^.*/files/(.*(js|css|png|jpg|jpeg|gif|ico))$ /wp-includes/ms-files.php?file=$1 last;
    expires 24h;
    log_not_found off;
    }

    location @wp {
    rewrite ^/files(.*) /wp-includes/ms-files.php?file=$1 last;

    rewrite ^(/[^/]+)?(/wp-.*) $2 last;
    rewrite ^(/[^/]+)?(/.*\.php) $2 last;

    rewrite ^/(.*)$ /index.php?q=$1 last;
    }

    location /doc/ {
    alias /usr/share/doc;
    autoindex on;
    allow 127.0.0.1;
    deny all;
    }

    include template.conf;
    #include wordpress.conf;

    }

    There are now no IF statments, and wordpress.conf is commented out.

    I now get directed to a signup page, a small step forward, but that means something is still not quite right.

    Thread Starter en3r0

    (@en3r0)

    Even using these settings from the nginx website give the same thing, a signup page. https://wiki.nginx.org/Wordpress

    Could it be something else?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    If you’re directed to the signup page, that means yuo don’t have a site for that subdomain.

    That is tech.ipstenu.org works, but foobar.ipstenu.org does not, since while I HAVE wildcard redirect, I have not defined a site as foobar. yet.

    Thread Starter en3r0

    (@en3r0)

    I have created a network site called test (text.example.com). When I click visit, I get directed to the signup page. Am I doing something wrong in the creation stage?

    I believe wildcard subdomains are set up right at the domain host. That is all I should need to do for that right?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    If you’re going to the signup page, wildcard redirects are good ??

    test.example.com SHOULD go to the ‘real’ site. Does test.example.com/wp-admin work?

    Thread Starter en3r0

    (@en3r0)

    It does not, it goes to the same signup page sadly.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    I really wish I knew more about nginx ??

    I didn’t go through your first post of this thread. Sorry.

    But, in your simplified configuration file as posted as reply to your own first post in (https://www.ads-software.com/support/topic/nginx-subdomain-sites-not-redirecting?replies=8#post-2553581), you are missing the following directive inside location / { }

    error_page 404 = @wp;

    Thread Starter en3r0

    (@en3r0)

    I never found a solution to this stuff really. Make sure you are clearing caches and cookies when logging into multisite after you set the configs.

    Also this made life a lot easier, I tried it and got things working.

    https://www.lowendbox.com/blog/wordpress-cheap-vps-lowendscript/

    Only takes about 5 min.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘nginx, subdomain, sites not redirecting’ is closed to new replies.