Bf358e0ab85c7bbb829ca8ddb4b237840994027d
By:
msatrya

Why subdomain redirect to parent domain in nginx?

July 29, 2015 1.8k views
LEMP Nginx

I googled and searched on DO for an answer but no luck. Here's the DNS record

$ORIGIN themephe.com.
$TTL 1800
themephe.com. IN SOA ns1.digitalocean.com. hostmaster.themephe.com. 1438156091 10800 3600 604800 1800
themephe.com. 1800 IN NS ns1.digitalocean.com.
themephe.com. 1800 IN NS ns2.digitalocean.com.
themephe.com. 1800 IN NS ns3.digitalocean.com.
themephe.com. 1800 IN A 104.131.10.228
themephe.com. 1800 IN MX 1 aspmx.l.google.com.
themephe.com. 1800 IN MX 5 alt1.aspmx.l.google.com.
themephe.com. 1800 IN MX 5 alt2.aspmx.l.google.com.
themephe.com. 1800 IN MX 10 alt3.aspmx.l.google.com.
themephe.com. 1800 IN MX 10 alt4.aspmx.l.google.com.
themephe.com. 1800 IN TXT v=spf1 a mx include:helpscoutemail.com ~all
googlemail._domainkey.themephe.com. 1800 IN TXT v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCPdRONTWENYHsEaI2flakR2j IHcHq+8tzPNPYBursA7bAy8utgSFBpG/miwdFoG+7a50NXdnixr7vY+2iVv+lFL4trX8AJMWwEYAdUjk vjvOjA/vvarfNRMLjoHNRcj9L4JcUT6MiT0RIkT/Yr5qgGN+CdSdOR9dkgWzfvIFIJ2wIDAQAB
demo.themephe.com. 1800 IN A 104.131.10.228

I tried this config in one file but not worked

server {
        listen 80;

        root /var/www/demo.themephe.com/htdocs;
        index index.php index.html index.htm;

        server_name demo.themephe.com;

        location / {
                try_files $uri $uri/ /index.php?query_string;
        }

        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

server {
    listen 80;
    server_name themephe.com;
    rewrite ^/(.*) https://themephe.com/$1 permanent;
}

server {
        listen 443 default_server;
        root /var/www/themephe.com/htdocs;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name themephe.com;

        # SSL
        ssl on;
        ssl_certificate /var/www/themephe.com/cert/themephe.com.chained.crt;
        ssl_certificate_key /var/www/themephe.com/cert/themephe.com.key;

        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}

        error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        # EDD
        location ~ ^/wp-content/uploads/edd/(.*?)\.zip$ {
                rewrite / permanent;
        }
}

I also tried to seperate the config file still not worked. Am i missing something?

2 Answers

check php-fpm
Chang it fastcgipass 127.0.0.1:9000; to fastcgipass 127.0.0.1:9001;
at both place hear and at php-fpm configuration file

  • I've not enabled it, please take a look at my config again. #fastcgi_pass 127.0.0.1:9000;. Or should I enable it?

  • I tried you suggestion, but then I couldn't restart nginx.

what error u got while restating nginx and restart php-fpm also and check error in /var/log/nginx/error.log

Have another answer? Share your knowledge.