0

I have had configured LEMP stack on my vps and set my "A" records to the server's IP address(v4). mydomin.com works pretty well as well as portfolio.mydomian.com in which I used just CSS and JS and indexed with *.html indexing. But on my blog part I have had use blog.mydomian.com and I configured it very well. and there is no error from NGNIX side, but wenn I try to open wordpress with blog.mydomain.com it returns the 404 Error. Does anybody here had same experience before, who may help me to solve ? I will share my mydomian.conf inside /etc/nginx/sites-available/mydomian.com here. thanks in advance

   server {
    listen 80;

    root /var/www/mydmoain.com/public_html;
    index index.html index.htm index.nginx-debian.html;

    access_log /var/www/mydmoain.com/access.log;

    server_name mydmoain.com www.mydmoain.com;

    location / {
           # try_files $uri $uri/ =404;

    }
}

server {
    listen 80;

    location / {
            root /var/www/portfolio.mydmoain.com/public_html;
            index index.html index.htm;
    }

    server_name portfolio.mydmoain.com;
    access_log /var/www/portfolio.mydmoain.com/access.log;
    error_log /var/www/portfolio.mydmoain.com/error.log;

}

server {
    listen 80;

    location / {
            root /var/www/blog.mydmoain.com/public_html; 
            index index.php index.html index.htm index.nginx-debian.html;
            try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
                    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                    include snippets/fastcgi-php.conf;
    }

   location ~ /\.ht {
             deny all;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all;        }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
             expires max;
             log_not_found off;
    }

    server_name blog.mydmoain.com;
    access_log /var/www/blog.mydmoain.com/access.log;
    error_log /var/www/blog.mydmoain.com/error.log;

}

  • 1
    Your root directive is in the wrong place. It needs to be within the server block so that it is inherited by all location blocks. At the moment, any file ending with .php will not be found. – Richard Smith Aug 21 '18 at 13:21
  • Hey @RichardSmith I have tried what you mentioned and it absolutely works. Thanks a lot – Ashkan Kamyab Aug 21 '18 at 18:23
0

I have changed the root directive to server block and it works pretty well, special thanks to @RichardSmith, who have had mentioned the problem. in case someone has the same Problem I will write a short explanation code.

server {
       listen 80;
       root /var/www/blog.mydomian.com
       server_name blog.mydomian.com www.blog.mydomian.com
       # the rest of configuration
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.