dongranding3909 2019-08-19 04:25
浏览 125

如何在同一域名下的同一个nginx服务器上运行angular和wordpress项目

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' );
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用