Question

Why subdomain redirect to parent domain in 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?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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

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