Nginx 如何在一个域中运行两个独立的应用程序?

Nginx 如何在一个域中运行两个独立的应用程序?,nginx,Nginx,我有两个应用程序。。。wordpress和WHMCS(计费应用程序) example.com是wordpress example.com/portal为WHMCS 在nginx服务器上,这里是我的文件夹 /example.com |_ /wordpress |_ /whmcs root是wordpress,但是当有人转到/portal时,我希望root是/whmcs 我试过root和alias。我要么被404,要么被403禁止 Here is my current example.conf f

我有两个应用程序。。。wordpress和WHMCS(计费应用程序)

example.com是wordpress

example.com/portal为WHMCS

在nginx服务器上,这里是我的文件夹

/example.com
|_ /wordpress
|_ /whmcs
root是wordpress,但是当有人转到/portal时,我希望root是/whmcs

我试过root和alias。我要么被404,要么被403禁止

Here is my current example.conf file

    server {
      listen 80;
      server_name example.com www.example.com;
      return 301 https://example.com$request_uri;
    }

    server {
      listen 80;
      listen 443 ssl;
      server_name example.com;
      ssl_certificate /etc/nginx/ssl.crt;
      ssl_certificate_key /etc/nginx/ssl.key;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers 'AES128+EECDH:AES128+EDH';
      ssl_prefer_server_ciphers on;
      ssl_session_cache shared:SSL:10m;
      root /usr/share/nginx/example/wordpress;

    location / {
      try_files $uri $uri/ /index.php?$query_string;
    }

    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 ^~ /portal/index.php {
      autoindex on;
      alias /usr/share/nginx/example/portal;
    }
    }

解决方案是不共享php位置

server {
      listen 80;
      server_name example.com;
      root /usr/share/nginx/example;

    location / {
    root /usr/share/nginx/example/wordpress;
    try_files $uri $uri/ /index.php?$query_string;
    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 /portal {
      error_page 404 = @whmcs; }

    location @whmcs {
      rewrite ^(.*)$ /portal/index.php last;
      root /usr/share/nginx/example/portal;
      try_files $uri $uri/ /index.php?$query_string; }

    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; }
      }