If I give the following
server {
listen 80;
server_name mywebsite.com;
root /a/b/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location /virtualLoc1 {
root /a/b/c;
location ~ \.php$ {
#PHP file forward to PHP-FPM
}
}
location /virtualLoc2/ {
alias /a/b/c/d/e/;
location ~ \.php(/|$) {
#PHP file forward to PHP-FPM
}
}
}
the http://mywebsite.com/virtualLoc2/ is not working where as http://mywebsite.com/virtualLoc1/ is working.
I'm using alias because I don't have virtual2 directory after /a/b/c/d/e/
but for virtualLoc1 there is a physical directory named virtualLoc1 after /a/b/d/c/virtualLoc1/.
Can anyone suggest what am I doing wrong here?
Related
Is it possible to have a suburl that point to a different root? For example:
www.domain.com/ -> /home/ubuntu/project1
www.domain.com/project2 -> /home/ubuntu/project2
I have this configuration at this moment but I'm getting a 404 when resolving domain.com/project2
server {
listen 80;
server_name domain.com;
root /home/ubuntu/project1;
location /project2 {
root /home/ubuntu/project2;
index index.html;
}
location / {
try_files $uri $uri/ /index.html;
}
}
It's because nginx will append the uri to root directive.
In your example config, accessing domain.com/project2 would try to look for a file named project2 in /home/ubuntu/project2 which is not found and return 404.
To solve your problem, try using alias directives.
server {
listen 80;
server_name domain.com;
root /home/ubuntu/project1;
location /project2 {
alias /home/ubuntu/project2;
index index.html;
}
location / {
try_files $uri $uri/ /index.html;
}
}
The current nginx conf I have looks like:
server {
listen 80;
server_name mydomain.com;
root /home/myname/some_app/public;
location / {
try_files $uri #some_named_location;
}
location /sub {
root /home/myname/other_app/public;
try_files $uri #other_named_location;
}
}
I expect mydomain.com/sub/xxx to be served by /home/myname/other_app/public/sub/xxx, but instead it's served by /home/myname/some_app/public/sub/xxx. What's going wrong here?
I also tried using alias instead of root in the /sub location block:
location /sub {
alias /home/myname/other_app/public;
try_files $uri #other_named_location;
}
Then I expect mydomain.com/sub/xxx to be served by /home/myname/other_app/public/xxx, but still it's served by /home/myname/some_app/public/sub/xxx.
I even tried moving the server block's root directive into the / location block.
server {
location / {
root /home/myname/some_app/public;
try_files $uri #some_named_location;
}
location /sub {
root /home/myname/other_app/public;
try_files $uri #other_named_location;
}
}
But it still doesn't work.
this is my site .conf file:
server {
listen [::]:80;
listen 80;
root /usr/share/nginx/html/suitecrm/;
index index.php index.html index.htm;
access_log /var/log/nginx/suitecrmaccess.log;
error_log /var/log/nginx/suitecrmerror.log error;
# Block access to stuff in the root
location ~* \.(pl|cgi|py|sh|lua|log|md5)$ {
return 444;
}
# Block access to data folders
location ~ /(soap|cache|upload|xtemplate|data|examples|include|log4php|metadata|modules|diagnostic|blowfish|emailmandelivery)/.*\.(php|pl|py|jsp|asp|sh|cgi|tpl|log|md5)$ {
return 444;
}
location / {
try_files $uri $uri/ =404;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
The paths are correct, I don't get what could be wrong here, any ideas please?
Have you looked at the suitecrm.log file to see what it says?
I'm using something like the following as a "default" vhost on Nginx. I want every sub domain to have an own directory basically.
Can anyone help with a fallback (I'm new to this). If a directory/sub domain doesn't exists I want some kind of custom 404.html page.
Thanks!
server {
server_name ~^(.+).mysite.com$;
set $root_path $1;
root /var/www/$root_path/public;
index index.html index.php;
location / {
try_files $uri /$uri /index.php?$args;
}
location ~ \.php$ {
#Include Nginx’s fastcgi configuration
include /etc/nginx/fastcgi.conf;
#Look for the FastCGI Process Manager at this location
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
client_max_body_size 100m;
}
}
Try this:
server {
...
error_page 404 /your_custom_404.html;
location = /your_custom_404.html {
root /path/to/your_custom_404.html;
internal;
}
location / {
try_files $uri $uri/ /index.php?$args =404;
}
...
}
What I'm trying to achieve is if someone visit my home/index page, I need to server my index.html file. But, if it's another URL/path pass the request to my index.php file (I'm using Symfony).
I follow this example, but is not working. It's always serving my PHP file.
server
{
listen 80;
server_name mysite.com;
root /path/to/my/web;
index index.html index.php;
location = /index.html
{
try_files $uri /index.html?$args;
}
location /
{
try_files $uri /index.php?$args;
}
}
I will appreciate any help or guidance you can share with me.
This finally worked for me:
server
{
listen 80;
server_name mysite.com;
root /path/to/my/web;
index index.html index.php;
location = /
{
try_files $uri /index.html?$args;
}
location /
{
try_files $uri /index.php?$args;
}
}