nginx, subdomain, sites not redirecting
-
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/*;
}
- The topic ‘nginx, subdomain, sites not redirecting’ is closed to new replies.