Welcome! Log In Create A New Profile

Advanced

Subdomain problem...

Posted by kiwisteve 
Subdomain problem...
September 19, 2012 04:23PM
Hello,

I'm having a problem configuring subdomains. When I goto mydomain.com or www.mydomain.com everything works as it should by resolving to www.mydomain.com.

However, when I go to dev.mydomain.com it resolves to www.dev.mydomain.com.

Why is it doing this?

What I'm hoping to do is have www.mydomain.com point to a Drupal 6 installation, and dev.mydomain.com point to a Drupal 7 install.

Below is my conf setup...

Thanks!

Steve

---
user www-data;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
# multi_accept on;
}

http {
server {
listen 80;
server_name dev.mydomain.com;
root /var/drupal-7.15;

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

location ~* \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
}

server {
listen 80;
listen 443 default ssl;
server_name mydomain.com www.mydomain.com;
ssl_protocols TLSv1 SSLv3;
ssl_certificate /home/certs/mydomain.com.crt;
ssl_certificate_key /home/certs/mydomain.key;

root /var/www;

client_max_body_size 8m;

if ($host !~* ^www\.) {
rewrite ^(.*)$ http://www.$host$1 permanent;
}

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

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

# This matters if you use drush
location = /backup {
deny all;
}

location ~* \.(txt|log)$ {
allow 192.168.0.0/16;
deny all;
}

location ~ \..*/.*\.php$ {
return 403;
}

location / {
try_files $uri @rewrite;
}

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

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}

location ~ ^/sites/.*/files/imagecache/ {
try_files $uri @rewrite;
}

location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}

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

include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Re: Subdomain problem...
October 04, 2012 01:38PM
I see one potential issue. It is in the following block:

if ($host !~* ^www\.) {
rewrite ^(.*)$ http://www.$host$1 permanent;
}

If I remember correctly, most apps written in C and C++ interpret ! to mean "not", so if $host no have www. in it, rewrite it so it does have www. in it. That is placed under the server block that looks for mysite.com and www.mysite.com. If you want it to look for both and load both from the same root, you can get rid of the rewrite.

If you do want it to go to www.mysite.com no matter what, what worked for me was to have a separate server block for mysite.com, with a rewrite there:

server {
listen 80;
server_name mysite.com;
rewrite ^ http://www.mysite.com$uri permanent;
}

--
Piki
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 189
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready