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;
}
}
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;
}
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 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 using Red Hat Enterprise server for hosting my phalcon based application. But after deployment the application is not working and showing "Please enable rewrite module on your web server to continue". I am using the below configuration in my default.conf file.
If any body has any idea plz help me to resolve the issue.
server {
listen 80;
server_name example.com www.example.com;
access_log /srv/www/example.com/log/access.log;
error_log /srv/www/example.com/log/error.log;
root /srv/www/example.com/public/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ #php_mvc;
}
location #php_mvc {
rewrite ^(.+)$ /index.php$1 last;
}
location ~ ^(.+\.php)(/.*)?$ {
fastcgi_split_path_info ^(.+\.php)(/.*)?$;
set $script_filename $document_root$fastcgi_script_name;
if (!-e $script_filename) {
return 404;
}
fastcgi_pass fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param APPLICATION_ENV development;
fastcgi_param SCRIPT_FILENAME $script_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Can you please try to add following code in your nginx configuration and check it again.
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /index.php?_url=$1;
}
This will work for you. (timeouts are high, you should change it for your app specs)
server {
listen 80 default_server;
server_name _;
client_max_body_size 128M;
location / {
root /var/www/public;
index index.php index.html index.htm;
try_files $uri $uri/ #rewrite;
fastcgi_connect_timeout 3000;
fastcgi_send_timeout 3000;
fastcgi_read_timeout 3000;
client_max_body_size 128M;
proxy_read_timeout 3000;
}
location #rewrite {
rewrite ^/(.*)$ /index.php?_url=$uri&$args;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /var/www/public;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location ~ "\.(js|ico|gif|jpg|png|jpeg|xls|csv)$" {
root /var/www/public;
}
location ~* \.(jpg|jpeg|png|gif|ico)$ {
expires 365d;
log_not_found off;
access_log off;
}
}
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