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;
}
Related
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 ;
}
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 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
I am relatively new to NGINX, I admit (less than 24 hours), but, I got it basically configured. I'm setting up a site for a friend, and I saw an example of some code that uses subdomains like in the code below. But, in the subdomain, PHP won't work. It just asks me to download the file if I go to "subdomain.domain.tld", but, if I go to "subdomain.domain.tld/index.php", it says "No input file specified." The subdomain is phpmyadmin, by the way.
server {
listen 80;
server_name irc.physibots.info;
rewrite (.*) http://physibots.info:3989;
}
server {
listen 80;
server_name "~^([a-z]+)?.physibots.info";
root /home/virtual/physibots.info/subdomains/$1;
index index.php index.html index.html;
location / {
autoindex on;
}
location ~ \.php {
try_files $uri /error.html
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
include fastcgi_params;
fastcgi_split_path_info ^((?U).+\.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;
}
}
#server {
# listen 443;
# server_name localhost;
#
# charset utf-8;
#
# ssl on;
# ssl_certificate
server {
listen 80;
server_name physibots.info default;
root /home/virtual/physibots.info/public_html;
index index.php index.html index.html;
location / {
autoindex on;
}
location ~ \.php {
try_files $uri /error.html
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
include fastcgi_params;
fastcgi_split_path_info ^((?U).+\.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;
}
}
Move the try_files to your location / { } block and change it to try_files $uri $uri/ /index.php;
location / {
autoindex on;
try_files $uri $uri/ /index.php;
}
location ~ \.php {
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
The rest looks surprisingly good for a beginner. :)
Also- make sure you're testing with curl and not a web browser or you'll constantly fight caching.