2

I installed a nginx webserver locally. The web root is under /var/www

Now I have a project which looks like this: /var/www /test-project /src /tests

The src folder is the folder, which contains the index.php file. Now I want to run the site when I enter https://localhost/test-project into the browser.

Currently this is my configuration:

server {
    listen          443;
    server_name     localhost;
    root            /var/www/;

    access_log  /usr/local/etc/nginx/logs/default-ssl.access.log  main;

    ssl                  on;
    ssl_certificate      ssl/localhost.crt;
    ssl_certificate_key  ssl/localhost.key;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    location / {
        try_files $uri $uri/ /index.php?$args;
        include   /usr/local/etc/nginx/conf.d/php-fpm;
    }

    location ~ /test-project { #/(?!Templates|uploads).* {
        try_files $uri/ $uri/ /test-project/src/index.php?$args;
        include   /usr/local/etc/nginx/conf.d/php-fpm;
    }

    error_page  404     /404.html;
    error_page  403     /403.html;
}

But currently I always get redirected to the 404 page. Can anybody tell me what I have to change to get it running?

1
  • Have you tried adding alias /var/www/test-project/src to the test-project location? – Joshua Griffiths Jul 5 '16 at 12:14
2

Keeping your root as is and assuming that the full path of your src folder is /var/www/test-project/src

I would then update the location for the test-project route to:

location /test-project/ {
    try_files $uri /test-project/src/index.php;
}

If your src folder's full path is: /var/www/src, then it would be:

location /test-project/ {
    try_files $uri /src/index.php;
}
2
  • I still get an error message: *1 directory index of "/var/www/test-project/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET /test-project/ HTTP/1.1", host: "localhost" But I tried to add a new root to the location or to add an alias. But non of them did work. – Pascal Jul 7 '16 at 9:32
  • a 403 error? If so there are some instructions in that article: 403 errors such as a chmod 755 on the directory – David B. Jul 8 '16 at 14:07
0

Your root should point to the folder where the index is located, otherwise you're doing (in my opinion) something wrong.

1
  • how would it look if i have different projects in the same folder /var/www – Pascal Jul 5 '16 at 12:02
0

Web root should be /var/www/test-project, as you are saying index.php is in src, and then go for https://localhost/src, also check your permissions and ownership.

Thanks

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.