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 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛