I have a problem with nginx and Symfony
I have a symfony app and it works when i follow the doc but i would like to make something like this
http://website.com/symfonyapp1 and http://website.com/symfonyapp2
here is my nginx config :
server {
server_name website.com;
location /symfonyapp1{
root /var/www/html/symfonyapp1/public;
# try to serve file directly, fallback to index.php
try_files $uri symfonyapp1 /index.php$is_args$args;
}
location ~ ^/symfonyapp1/public/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
}
here is my /etc/hosts file
XXX.XXX.XX.XX website1.local symfonyapp1
XXX.XXX.XX.XX website2.local symfonyapp2
if someone can help me it can be very helpful
Thanks in advance
Related
I have a virtual server with nginx, with my Symfony project installed in /var/www/test. In /etc/nginx/site-avalible/test.conf I create this config:
server {
server_name test.dev www.test.dev;
root /var/www/test/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/test_error.log;
access_log /var/log/nginx/test_access.log;
}
and then create symlink:
ln -s /etc/nginx/sites-available/test.conf /etc/nginx/sites-enabled/test.conf
and add rules to /etc/hosts:
127.0.0.1 test.dev
this is all done in the server. Then I know the IP of my virtual server and I create in my local computer in /etc/hosts:
82.91.183.61 test.dev
and then try to open in my browser but have a 502 error, why? And how can I correct the virtual host config for nginx and how do I open my project in my local computer if I know the IP and can create a virtual host?
I'm trying to install simplesaml on nginx web server and I'm running into a problem with the alias, a friend told me to use rewrite and gave me the example below, but his example doesn't work either.
rewrite ^/simplesaml/module.php/(.*) /simplesaml/www/module.php?path=$1 last;
rewrite ^/simplesaml/(.*)$ /simplesaml/www/$1 last;
How can I fix this, I'm busting my head since 2 days now,I'm out of ideas.
root /home/mihaela/public_html;
I've been having the same issue and this config is the only one I've found to work.
Example NGINX config
Here are my nginx configs:
This is my central IDP config
server {
listen 80 default_server;
server_name saml.local;
root /srv/sites/saml.local/www/;
index index.php;
location ~ \.php(/|$) {
fastcgi_keep_conn on;
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_URL $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_hide_header X-Powered-By;
fastcgi_pass 127.0.0.1:9000;
}
}
And here is my config for simplesaml accessible via /saml
location /saml {
alias /srv/sites/site.local/vendor/simplesamlphp/www;
index index.php;
location ~ ^(?<prefix>/saml)(?<phpfile>.+?\.php)(?<pathinfo>/.*)?$ {
fastcgi_param SCRIPT_FILENAME $document_root$phpfile;
fastcgi_param PATH_INFO $pathinfo if_not_empty;
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
fastcgi_pass 127.0.0.1:9000;
}
}
I have a Symfony2 project and I want to add a WordPress blog in /web/blog directory.
I need to know how can I configure the virtualhost to run both. My current configuration is:
server {
listen 80;
server_name my-project.local;
root /var/www/my-project/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
error_log /var/log/nginx/protox_error.log;
access_log /var/log/nginx/protox_access.log;
}
Can you help me?
I'm trying to host a symfony app in a virtual folder and using url rewriting with nginx.
Following various examples I found, I'm stuck with something like that:
upstream phpfcgi {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 443;
server_name localhost;
root /realpath/Symfony/web/;
[ssl stuff]
# strip app.php/ prefix if it is present
rewrite ^/app_dev\.php/?(.*)$ /$1 permanent;
location /virtual{
alias /realpath/Symfony/web/;
index app_dev.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^/virtual/(.*)$ /app_dev.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass phpfcgi;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
}
}
If I remove the /virtual from the two first locations , it's working fine.
Should I set the SCRIPT_URI on the third location?
Thanks for your help
Here is the solution, see the added line:
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass phpfcgi;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Add this line:
fastcgi_param SCRIPT_NAME /virtual$fastcgi_script_name;
fastcgi_param HTTPS on;
}
My folder structure is as follows:
/www
/api.domain.tld
/app.domain.tld
The API contains the system it self and APP implements the API via HTTP.
I want to create an Nginx server for app.domain.tld that also contains an "virtual directory" for API.
You can contact the API likes this: http://api.domain.tld/method/api.json
But it would be great if the API can be contacted like this also: http://app.domain.tld/api/method/api.json without copying something into APP, but keep those two "systems" separated.
What I have for now:
server {
listen 80;
root /var/www/app.domain.tld;
index index.php index.html;
server_name app.domain.tld;
location ^~ /api {
alias /var/www/api.domain.tld;
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;
}
rewrite ^/api/([a-z]+)/api.json$ /api.php?method=$1 last;
}
location....
location....
location....
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;
}
}
Unfortunately this does now works as expected.
The rewrite does not work at all. I can get api.domain.tld/index.php but when it needs to use the rewrite, it will not work.
I have tried several things. Either I get 404 or 403 with this error:
directory index of [path] is forbidden
Can someone come up with a better solution that actually works?
Regards
You should change SCRIPT_FILENAME path:
server {
listen 80;
root /var/www/app.domain.tld;
index index.php index.html;
location ~ ^/api/(.+\.php)$ {
alias /www/api.domain.tld/public/$1;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}