2

I need my Drupal 8 website to be served from within a subdirectory of my NGINX_SERVER_ROOT but is doesn't work.

Drupal should be reached at mydomain.com/drupal.

My NGINX_SERVER_ROOT is /var/www/html/web.

When the source code is in /var/www/html/web it works fine. But when moved to /var/www/html/web/drupal and I try to reach mydomain.com/drupal, it doesn't work.

I have edited the .htaccess file within the drupal subfolder and set RewriteBase /drupal as explained in the file itself.

Here is the log when I try to access my Drupal installation.

nginx_1    | 2018/10/09 12:58:38 [error] 42#42: *5 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.160.4, server: default, request: "GET /drupal HTTP/1.1", upstream: "fastcgi://192.168.160.5:9000", host: "d8site.local:8000"
nginx_1    | 192.168.160.4 - - [09/Oct/2018:12:58:38 +0000] "GET /drupal HTTP/1.1" 404 47 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
nginx_1    | 192.168.160.4 - - [09/Oct/2018:12:58:38 +0000] "GET /favicon.ico HTTP/1.1" 200 43 "http://d8site.local:8000/drupal" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"

Could someone point me in the right direction?

2
  • .htaccess is Apache-specific - when you're serving your homepage with Nginx that file is completly ignored. You need to modify your Nginx settings.
    – Hudri
    Oct 9, 2018 at 13:55
  • Thanks. I realized that in the meantime. Any guidance on how to modify Nginx for this situation?
    – MrUpsidown
    Oct 9, 2018 at 14:19

1 Answer 1

2

You have to edit the nginx virtual host file of your website. You'll usually find it at /etc/nginx/sites-available/yoursitename.vhost.

Open it with write permissions, and edit root directive at the top of server block as following:

server {
    listen x.x.x.x:yyyy; #IP:port
    server_name www.example.com;
    root /var/www/html/web/drupal;

Save the file and reload nginx conf : sudo systemctl reload nginx.service

1
  • Thanks, I'll have to check that. I switched to a different setup for now but I'll definitely try that at a later point.
    – MrUpsidown
    Nov 1, 2018 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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