We are trying to run https://www.planify.in on angular and https://www.planify.in/blog with wordpress on same nginx. But facing challenge in it. We are able to run angular on main domain. For running blog on /blog, we have tried multiple approach in nginx but none of it seems to be working. Everytime, we are getting a file which is getting downloaded when we try to open blog rather than rendering the php file. It is rendering the file.
a) First approach we tried in nginx config:
location ^~/blog/ {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
b) Second approach we tried:
location = /blog {
return 301 /blog/;
}
c) Third approach we tried:
location /blog {
resolver 8.8.8.8;
proxy_pass https://127.0.0.1:8080;
if ($request_method !~ ^(GET|HEAD|POST)$ ){
d) Fourth approach we tried:
location /blog {
index index.php
root /var/www/planify.in/blog/index.html
}
Even tried putting /blog/public instead of /blog/index.html
server {
listen 80;
listen [::]:80;
listen 443;
ssl on;
ssl_certificate /opt/certificate.pem;
ssl_certificate_key /opt/key.key;
root /var/www/planify.in;
index index.html index.htm index.nginx-debian.html;
server_name planify.in www.planify.in;
client_max_body_size 50M;
location = /xmlrpc.php {
deny all;
}
location /blog {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location / {
proxy_pass_request_headers on;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
rewrite ^/(/.*|$) /$1 break;
proxy_pass http://127.0.0.1:3014;
}
location ~ \.php$ {
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;
}
# location ~ ^/openproject(/.*|$) {
# proxy_pass_request_headers on;
# proxy_set_header X-Forwarded-Host $host;
# proxy_set_header X-Forwarded-Server $host;
# proxy_set_header X-Forwarded-For
# $proxy_add_x_forwarded_for;
# proxy_pass http://127.0.0.1:6000;
# }
location ~ ^/planningboard(/.*|$) {
proxy_pass_request_headers on;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
rewrite ^/planningboard(/.*|$) /$1 break;
proxy_pass http://127.0.0.1:3010;
}
location = /planningboard {
return 301 /planningboard/;
}
location ~ ^/home(/.*|$) {
proxy_pass_request_headers on;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
rewrite ^/home(/.*|$) /$1 break;
proxy_pass http://127.0.0.1:3014;
}
location = /home {
return 301 /home/;
}
}
server {
listen 8443;
ssl on;
ssl_certificate /opt/certificate.pem;
ssl_certificate_key /opt/key.key;
root /var/www/planify.in;
index index.html index.htm index.nginx-debian.html;
server_name planify.in www.planify.in;
client_max_body_size 50M;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
This is the file which is being downloaded:
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );