I have an Ubuntu server with Nginx running node and PHP both.
Requirements:
- www.example.com/ -> React App (Running with PM2)
- www.example.com/blog -> Running a WordPress Blog
- www.example.com/backend -> Running a Symfony app which is the API
Achieved:
- React App with PM2
- WordPress blog running at /blog with index.php rewrite.
Problem:
Symfony app that is supposed to run on /backend is instead running on /backend/web/app_dev.php and additionally app.php (production mode) throwing a 500 server error. (SCREENSHOTS ATTACHED)
The Nginx configuration is as follows:
# Default Server Settings
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php app.php;
server_name 100.100.100.100;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3030/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
# WORDPRESS SETTINGS
location @blog {
rewrite ^/blog(.*) /blog/index.php?q=$1;
}
location /blog {
index index.php
alias /var/www/html/blog;
try_files $uri $uri/ @blog;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
access_log /var/log/nginx/blog-access.log;
error_log /var/log/nginx/blog-error.log;
}
# SYMFONY SETTINGS
location @backend {
rewrite ^/backend(.*)$ /web/app.php/$1 last;
}
location /backend {
index app.php
alias /var/www/html/backend/web;
try_files $uri $uri/ @backend;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
access_log /var/log/nginx/symposh-access.log;
error_log /var/log/nginx/symposh-error.log;
}
location ~ /\.ht {
deny all;
}
}
UPDATED SYMFONY SETTINGS (Still not working):
# SYMFONY SETTINGS
location /backend {
index app.php;
alias /var/www/html/backend/web;
try_files $uri $uri/ /backend/web/app.php?$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
access_log /var/log/nginx/symposh-access.log;
error_log /var/log/nginx/symposh-error.log;
}
RESULT: