Nginx Virtual Directory using the same root gives 404 error












2















I'm fairly new to Nginx, and I'm attempting to import legacy sites from Apache. I want to get rid of the virtual directories but unfortunately I cannot.



The virtual directories point to the same root at the primary site. There is logic in the code that detects the virtual directory and loads data based on that information, which is why it's there.



Here is the config I'm attempting to get to work:



server {
listen 80;

large_client_header_buffers 4 32k;

server_name site.domain.com;

access_log /var/log/sites/site.access.log;
error_log /var/log/sites/site.error.log error;


location / {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}

location /sitea {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}

location ~ /.ht {
deny all;
}
}


Contents of php.inc:



location ~ .php$ {
include snippets/fastcgi-php.conf;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}


I have tried every thing that google has to offer to get this to work, but no matter what I do I continue to get the following error:



2018/11/15 20:28:32 [debug] 5056#5056: *1 http script var: "/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "/sitea/index.php" "/var/www/php/site/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "=404" "/var/www/php/site=404"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http finalize request: 404, "/sitea/index.php?requestType=home" a:1, c:1
2018/11/15 20:28:32 [debug] 5056#5056: *1 http special response: 404, "/sitea/index.php?requestType=home"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http set discard body
2018/11/15 20:28:32 [debug] 5056#5056: *1 xslt filter header
2018/11/15 20:28:32 [debug] 5056#5056: *1 HTTP/1.1 404 Not Found


Any help towards the right direction will be appreciated.



Note: it also does the same thing using the alias vs root



With alias I get the following:




2018/11/15 20:37:38 [error] 5189#5189: *1 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: #.#.#.#, server: site.domain.com, request: "GET
/sitea/index.php?requestType=home HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "site.domain.com"




Possible Solution



I'm not sure if this is the proper way of doing it, but it worked.



If I created a symbolic link for the virtual directory in the main folder the site loaded. I'd rather do this in Nginx, but if I have to go this route I will. Thoughts?










share|improve this question

























  • What is the location of the file whose URI is /sitea/index.php?

    – Richard Smith
    Nov 15 '18 at 22:37











  • /var/www/php/site thanks

    – CodeLikeBeaker
    Nov 15 '18 at 23:05


















2















I'm fairly new to Nginx, and I'm attempting to import legacy sites from Apache. I want to get rid of the virtual directories but unfortunately I cannot.



The virtual directories point to the same root at the primary site. There is logic in the code that detects the virtual directory and loads data based on that information, which is why it's there.



Here is the config I'm attempting to get to work:



server {
listen 80;

large_client_header_buffers 4 32k;

server_name site.domain.com;

access_log /var/log/sites/site.access.log;
error_log /var/log/sites/site.error.log error;


location / {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}

location /sitea {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}

location ~ /.ht {
deny all;
}
}


Contents of php.inc:



location ~ .php$ {
include snippets/fastcgi-php.conf;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}


I have tried every thing that google has to offer to get this to work, but no matter what I do I continue to get the following error:



2018/11/15 20:28:32 [debug] 5056#5056: *1 http script var: "/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "/sitea/index.php" "/var/www/php/site/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "=404" "/var/www/php/site=404"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http finalize request: 404, "/sitea/index.php?requestType=home" a:1, c:1
2018/11/15 20:28:32 [debug] 5056#5056: *1 http special response: 404, "/sitea/index.php?requestType=home"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http set discard body
2018/11/15 20:28:32 [debug] 5056#5056: *1 xslt filter header
2018/11/15 20:28:32 [debug] 5056#5056: *1 HTTP/1.1 404 Not Found


Any help towards the right direction will be appreciated.



Note: it also does the same thing using the alias vs root



With alias I get the following:




2018/11/15 20:37:38 [error] 5189#5189: *1 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: #.#.#.#, server: site.domain.com, request: "GET
/sitea/index.php?requestType=home HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "site.domain.com"




Possible Solution



I'm not sure if this is the proper way of doing it, but it worked.



If I created a symbolic link for the virtual directory in the main folder the site loaded. I'd rather do this in Nginx, but if I have to go this route I will. Thoughts?










share|improve this question

























  • What is the location of the file whose URI is /sitea/index.php?

    – Richard Smith
    Nov 15 '18 at 22:37











  • /var/www/php/site thanks

    – CodeLikeBeaker
    Nov 15 '18 at 23:05
















2












2








2








I'm fairly new to Nginx, and I'm attempting to import legacy sites from Apache. I want to get rid of the virtual directories but unfortunately I cannot.



The virtual directories point to the same root at the primary site. There is logic in the code that detects the virtual directory and loads data based on that information, which is why it's there.



Here is the config I'm attempting to get to work:



server {
listen 80;

large_client_header_buffers 4 32k;

server_name site.domain.com;

access_log /var/log/sites/site.access.log;
error_log /var/log/sites/site.error.log error;


location / {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}

location /sitea {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}

location ~ /.ht {
deny all;
}
}


Contents of php.inc:



location ~ .php$ {
include snippets/fastcgi-php.conf;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}


I have tried every thing that google has to offer to get this to work, but no matter what I do I continue to get the following error:



2018/11/15 20:28:32 [debug] 5056#5056: *1 http script var: "/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "/sitea/index.php" "/var/www/php/site/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "=404" "/var/www/php/site=404"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http finalize request: 404, "/sitea/index.php?requestType=home" a:1, c:1
2018/11/15 20:28:32 [debug] 5056#5056: *1 http special response: 404, "/sitea/index.php?requestType=home"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http set discard body
2018/11/15 20:28:32 [debug] 5056#5056: *1 xslt filter header
2018/11/15 20:28:32 [debug] 5056#5056: *1 HTTP/1.1 404 Not Found


Any help towards the right direction will be appreciated.



Note: it also does the same thing using the alias vs root



With alias I get the following:




2018/11/15 20:37:38 [error] 5189#5189: *1 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: #.#.#.#, server: site.domain.com, request: "GET
/sitea/index.php?requestType=home HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "site.domain.com"




Possible Solution



I'm not sure if this is the proper way of doing it, but it worked.



If I created a symbolic link for the virtual directory in the main folder the site loaded. I'd rather do this in Nginx, but if I have to go this route I will. Thoughts?










share|improve this question
















I'm fairly new to Nginx, and I'm attempting to import legacy sites from Apache. I want to get rid of the virtual directories but unfortunately I cannot.



The virtual directories point to the same root at the primary site. There is logic in the code that detects the virtual directory and loads data based on that information, which is why it's there.



Here is the config I'm attempting to get to work:



server {
listen 80;

large_client_header_buffers 4 32k;

server_name site.domain.com;

access_log /var/log/sites/site.access.log;
error_log /var/log/sites/site.error.log error;


location / {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}

location /sitea {
root /var/www/php/site;
index index.php;
include /etc/nginx/conf.d/php.inc;
}

location ~ /.ht {
deny all;
}
}


Contents of php.inc:



location ~ .php$ {
include snippets/fastcgi-php.conf;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}


I have tried every thing that google has to offer to get this to work, but no matter what I do I continue to get the following error:



2018/11/15 20:28:32 [debug] 5056#5056: *1 http script var: "/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "/sitea/index.php" "/var/www/php/site/sitea/index.php"
2018/11/15 20:28:32 [debug] 5056#5056: *1 trying to use file: "=404" "/var/www/php/site=404"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http finalize request: 404, "/sitea/index.php?requestType=home" a:1, c:1
2018/11/15 20:28:32 [debug] 5056#5056: *1 http special response: 404, "/sitea/index.php?requestType=home"
2018/11/15 20:28:32 [debug] 5056#5056: *1 http set discard body
2018/11/15 20:28:32 [debug] 5056#5056: *1 xslt filter header
2018/11/15 20:28:32 [debug] 5056#5056: *1 HTTP/1.1 404 Not Found


Any help towards the right direction will be appreciated.



Note: it also does the same thing using the alias vs root



With alias I get the following:




2018/11/15 20:37:38 [error] 5189#5189: *1 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: #.#.#.#, server: site.domain.com, request: "GET
/sitea/index.php?requestType=home HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "site.domain.com"




Possible Solution



I'm not sure if this is the proper way of doing it, but it worked.



If I created a symbolic link for the virtual directory in the main folder the site loaded. I'd rather do this in Nginx, but if I have to go this route I will. Thoughts?







nginx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 21:00







CodeLikeBeaker

















asked Nov 15 '18 at 20:33









CodeLikeBeakerCodeLikeBeaker

13.5k126090




13.5k126090













  • What is the location of the file whose URI is /sitea/index.php?

    – Richard Smith
    Nov 15 '18 at 22:37











  • /var/www/php/site thanks

    – CodeLikeBeaker
    Nov 15 '18 at 23:05





















  • What is the location of the file whose URI is /sitea/index.php?

    – Richard Smith
    Nov 15 '18 at 22:37











  • /var/www/php/site thanks

    – CodeLikeBeaker
    Nov 15 '18 at 23:05



















What is the location of the file whose URI is /sitea/index.php?

– Richard Smith
Nov 15 '18 at 22:37





What is the location of the file whose URI is /sitea/index.php?

– Richard Smith
Nov 15 '18 at 22:37













/var/www/php/site thanks

– CodeLikeBeaker
Nov 15 '18 at 23:05







/var/www/php/site thanks

– CodeLikeBeaker
Nov 15 '18 at 23:05














1 Answer
1






active

oldest

votes


















1














The root directive constructs the path to the file by the simple concatenation of its value with the current URI. So your second location block is looking for the file at /var/www/php/site/sitea/index.php.



The alias directive within a prefix location will replace the prefix text with the alias value. See this document for more.



location /sitea {
alias /var/www/php/site;
...
}


So the above location block will look for the URI /sitea/index.php at /var/www/php/site/index.php.



Both the root and alias directives set a variable called $request_filename to the path to the file.



In your PHP block, you use $document_root$fastcgi_script_name to inform PHP-FPM of the path to the file. This works with root but not with alias.



fastcgi_param SCRIPT_FILENAME $request_filename;


The above works with both root and alias for PHP blocks which do not process path info (such as yours).






share|improve this answer
























  • Thank you for the details explanation. Using alias and fastcgi_param SCRIPT_FILENAME $request_filename it got past that error. The site didn't didn't load, but that might be something else in code. Thanks again!

    – CodeLikeBeaker
    Nov 16 '18 at 13:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327496%2fnginx-virtual-directory-using-the-same-root-gives-404-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The root directive constructs the path to the file by the simple concatenation of its value with the current URI. So your second location block is looking for the file at /var/www/php/site/sitea/index.php.



The alias directive within a prefix location will replace the prefix text with the alias value. See this document for more.



location /sitea {
alias /var/www/php/site;
...
}


So the above location block will look for the URI /sitea/index.php at /var/www/php/site/index.php.



Both the root and alias directives set a variable called $request_filename to the path to the file.



In your PHP block, you use $document_root$fastcgi_script_name to inform PHP-FPM of the path to the file. This works with root but not with alias.



fastcgi_param SCRIPT_FILENAME $request_filename;


The above works with both root and alias for PHP blocks which do not process path info (such as yours).






share|improve this answer
























  • Thank you for the details explanation. Using alias and fastcgi_param SCRIPT_FILENAME $request_filename it got past that error. The site didn't didn't load, but that might be something else in code. Thanks again!

    – CodeLikeBeaker
    Nov 16 '18 at 13:25
















1














The root directive constructs the path to the file by the simple concatenation of its value with the current URI. So your second location block is looking for the file at /var/www/php/site/sitea/index.php.



The alias directive within a prefix location will replace the prefix text with the alias value. See this document for more.



location /sitea {
alias /var/www/php/site;
...
}


So the above location block will look for the URI /sitea/index.php at /var/www/php/site/index.php.



Both the root and alias directives set a variable called $request_filename to the path to the file.



In your PHP block, you use $document_root$fastcgi_script_name to inform PHP-FPM of the path to the file. This works with root but not with alias.



fastcgi_param SCRIPT_FILENAME $request_filename;


The above works with both root and alias for PHP blocks which do not process path info (such as yours).






share|improve this answer
























  • Thank you for the details explanation. Using alias and fastcgi_param SCRIPT_FILENAME $request_filename it got past that error. The site didn't didn't load, but that might be something else in code. Thanks again!

    – CodeLikeBeaker
    Nov 16 '18 at 13:25














1












1








1







The root directive constructs the path to the file by the simple concatenation of its value with the current URI. So your second location block is looking for the file at /var/www/php/site/sitea/index.php.



The alias directive within a prefix location will replace the prefix text with the alias value. See this document for more.



location /sitea {
alias /var/www/php/site;
...
}


So the above location block will look for the URI /sitea/index.php at /var/www/php/site/index.php.



Both the root and alias directives set a variable called $request_filename to the path to the file.



In your PHP block, you use $document_root$fastcgi_script_name to inform PHP-FPM of the path to the file. This works with root but not with alias.



fastcgi_param SCRIPT_FILENAME $request_filename;


The above works with both root and alias for PHP blocks which do not process path info (such as yours).






share|improve this answer













The root directive constructs the path to the file by the simple concatenation of its value with the current URI. So your second location block is looking for the file at /var/www/php/site/sitea/index.php.



The alias directive within a prefix location will replace the prefix text with the alias value. See this document for more.



location /sitea {
alias /var/www/php/site;
...
}


So the above location block will look for the URI /sitea/index.php at /var/www/php/site/index.php.



Both the root and alias directives set a variable called $request_filename to the path to the file.



In your PHP block, you use $document_root$fastcgi_script_name to inform PHP-FPM of the path to the file. This works with root but not with alias.



fastcgi_param SCRIPT_FILENAME $request_filename;


The above works with both root and alias for PHP blocks which do not process path info (such as yours).







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 9:13









Richard SmithRichard Smith

21.4k42641




21.4k42641













  • Thank you for the details explanation. Using alias and fastcgi_param SCRIPT_FILENAME $request_filename it got past that error. The site didn't didn't load, but that might be something else in code. Thanks again!

    – CodeLikeBeaker
    Nov 16 '18 at 13:25



















  • Thank you for the details explanation. Using alias and fastcgi_param SCRIPT_FILENAME $request_filename it got past that error. The site didn't didn't load, but that might be something else in code. Thanks again!

    – CodeLikeBeaker
    Nov 16 '18 at 13:25

















Thank you for the details explanation. Using alias and fastcgi_param SCRIPT_FILENAME $request_filename it got past that error. The site didn't didn't load, but that might be something else in code. Thanks again!

– CodeLikeBeaker
Nov 16 '18 at 13:25





Thank you for the details explanation. Using alias and fastcgi_param SCRIPT_FILENAME $request_filename it got past that error. The site didn't didn't load, but that might be something else in code. Thanks again!

– CodeLikeBeaker
Nov 16 '18 at 13:25




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327496%2fnginx-virtual-directory-using-the-same-root-gives-404-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine