With the following configuration, http://mysite works, but http://mysite/test always gives NOT FOUND. Why?
server {
listen 80 ;
listen [::]:80 ;
server_name mysite;
root /home/developer/www;
error_log /var/log/nginx/test_error.log;
client_body_timeout 5s;
client_header_timeout 5s;
index index.php index.html index.htm;
location / {
root /home/developer/www/mysiste-admin;
try_files $uri $uri/ /index.php?$args;
}
location /test/ {
root /home/developer/www/mysite-test;
error_log /var/log/nginx/test_error.log ;
limit_req zone=http burst=20 delay=8;
limit_conn addr 10;
try_files $uri $uri/ /index.php?args ;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
location ~ /test/.+\.php$ {
allow 127.0.0.1;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
#we are directly using the $request_filename as its a single php script
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
location ~ \.php$ {
limit_req zone=http burst=20 delay=8;
limit_conn addr 10;
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
The solution is to use alias and the correct try_files directive:
location /test/ {
alias /home/developer/www/mysite.test;
error_log /var/log/nginx/test_error.log ;
limit_req zone=http burst=20 delay=8;
limit_conn addr 10;
try_files $uri $uri /mysite-test/index.php$args ;
}
Related
Please tell me how to configure nginx so that it serves a file
/var/www/public/frontend/index.html
for all requests except
/api/
For api should give
/var/www/public/index.php
Tried using
server {
listen 80;
server_name localhost;
root /var/www/public;
location /api/ {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
}
server {
listen 80;
server_name localhost;
root /var/www/public/frontend;
location / {
try_files $uri $uri/ /index.html?$query_string;
}
}
and
server {
listen 80;
server_name localhost;
root /var/www/public;
location /api/ {
try_files $uri $uri/ /index.php?$query_string;
}
location / {
try_files $uri $uri/ /frontend/index.html?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
}
But it doesn't work. Either one or the other works. I know that it would be possible to make a subdomain, but at the moment I need to do without it
The first one definitely won't work, you should use only one server block for this case. For the second one, you cantry either
location / {
try_files /frontend$uri /frontend$uri/ /frontend/index.html?$query_string;
}
or
location / {
root /var/www/public/frontend;
try_files $uri $uri/ /index.html?$query_string;
}
I'm trying to run 2 applications on the server...
first application on the root document (wordpress)
and second application in a folder /app (symfony4)
The problem is that i an't find the way to use the alias on the nested folder...
my config file:
server {
listen 80;
server_name ~^(?<folder>[^.]*).magana.dev.hexis.fr;
charset utf-8;
index index.php index.html index.htm;
root /var/www/projects/dev/magana/$folder/htdocs;
access_log /var/www/projects/dev/magana/$folder/access.log;
error_log /var/www/projects/dev/commons/logs/magana_error.log;
client_max_body_size 200M;
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|js|css)$ {
access_log off;
log_not_found off;
expires 30d;
add_header Pragma "public";
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV magana;
include fastcgi_params;
fastcgi_read_timeout 600;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SERVER_NAME $folder.magana.dev.hexis.fr;
}
location /app {
alias /var/www/projects/dev/magana/$folder/htdocs/app/public;
try_files $uri $uri/ #app;
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location #app {
rewrite /app/(.*)$ /app/public/index.php?/$1 last;
}
location ~ /\.ht {
deny all;
}
}
What i'm missing?
Thanks for your help
Whit this code i can access the application but I still don't find the way to declare e=the kernelrootdirectory
server {
listen 80;
server_name ~^(?<folder>[^.]*).magana.dev.example.fr;
charset utf-8;
index index.php index.html index.htm;
set $symfonyRoot /var/www/projects/dev/magana/$folder/htdocs/app/public;
set $symfonyScript index.php;
root /var/www/projects/dev/magana/$folder/htdocs;
access_log /var/www/projects/dev/magana/$folder/access.log;
error_log /var/www/projects/dev/commons/logs/magana_error.log;
client_max_body_size 200M;
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp$
access_log off;
log_not_found off;
expires 30d;
add_header Pragma "public";
}
location /app {
root $symfonyRoot;
rewrite ^/app/(.*)$ /$1 break;
try_files $uri #symfonyFront;
}
location #symfonyFront {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $symfonyRoot/$symfonyScript;
fastcgi_param SCRIPT_NAME /app/$symfonyScript;
fastcgi_param REQUEST_URI /app$uri?$args;
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV magana;
include fastcgi_params;
fastcgi_read_timeout 600;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SERVER_NAME $folder.magana.dev.hexis.fr;
}
location ~ /\.ht {
deny all;
}
}
I'm trying to setup nginx to begin working with phalcon, here's the config :
server {
listen 80;
server_name localhost.dev;
set $root_path '/usr/share/nginx/html/phalcon/public';
root $root_path;
index index.php index.html index.htm;
charset utf-8;
rewrite_log on;
location / {
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path/public;
}
location ~ /\.ht {
deny all;
}
}
I tried all possibilites but still I can't get it working.
Any clues?
look here
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
I am trying to setup my Laravel 4 project using nginx . Here is my nginx server block for laravel :
server {
listen 80;
root /home/prism/www/laravel/public;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
But my problem is , Its showing "404 not found" error for all other routes except the default one , that comes with default installation .
This is an NGINX Configuration i've used with Laravel 4 and Laravel 4.1 that works.
server {
listen 80;
server_name sub.domain.com;
set $root_path '/var/www/html/application_name/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
you could try this for location / { ... }
location / {
try_files $uri $uri/ /index.php?$query_string;
}
$query_string worked for me.
I'm trying to install Symfony on my php5-fpm+nginx server on ubuntu.
When i'm entering to /web/app_dev.php it's displaying an error :
An error occurred while loading the web debug toolbar (404: Not
Found).
Do you want to open the profiler?
When i'm entering to profiler(/web/app_dev.php/_profiler/0db7ac) it tells:
No input file specified.
I know there is a problem with my server configuration file. Here it is:
server {
listen 80;
# listen [::]:80 ipv6only=on;
root /home/marker/Projects/stereoshoots/www;
access_log /home/marker/Projects/stereoshoots/logs/access.log;
server_name stereoshoots.local;
index index.php index.html index.htm;
location / {
autoindex on;
# try_files $uri $uri/ #rewrite;
try_files $uri $uri/ /index.php;
}
# location #rewrite {
# rewrite ^/(.*)$ /index.php?q=$1;
# }
location ~* \.(jpg|jpeg|gif|css|png|js|ico|xml|txt)$ {
access_log off;
expires 30d;
}
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
What should i edit, to get symfony installed right?
Thanks!
I think the only thing left is to pass the uri to the index.php
try_files $uri $uri/ /index.php$request_uri
Do you really have index.php?
Try this:
index app_dev.php;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /app_dev.php/$1;
}
location ~ \.php {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_PORT 80;
fastcgi_param SERVER_NAME stereoshoots.local;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index app_dev.php;
}
Notice that I changed location ~ \.php$ to location ~ \.php