如何在与AngularJS相同vhost的ubuntu 16.4下子目录下安装WordPress

时间:2019-12-18 作者:Lim Socheat

我有主域的vhostwww.example.com. 我想在一个名为news (www.example.com/news/).

这是vhost配置文件。

server {
  server_name www.example.com;
  return 301 $scheme://example.com$request_uri;
}

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

server {
  listen 443 ssl;
  server_name example.com www.example.com;

  ssl_certificate /etc/ssl/bundle_example.com.crt;
  ssl_certificate_key /etc/ssl/example.com_private_key.key;


  location / {
    root /www/sites/Yoga-Frontend/dist/Yoga-Frontend;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
  }
  location /news {
    root /www/sites/Yoga-Frontend/dist/Yoga-Frontend/news;
    index index.php;
    try_files $uri $uri/ /news/index.php?$args /news/index.php?q=$uri&$args;

    access_log /var/log/nginx/blog.access.log;
    error_log /var/log/nginx/blog.error.log;

    location ~ \\.php$ {
      include snippets/fastcgi-php.conf;
      fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }
  }
}
问题:一旦我进入www.example.com/news/, 它总是重定向到www.example.com.

1 个回复
SO网友:Lim Socheat

我找到了答案

server {
  server_name www.example.com;
  return 301 $scheme://example.com$request_uri;
}

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

server {
  listen 443 ssl;
  server_name example.com www.example.com;

  root /www/sites/Yoga-Frontend/dist/Yoga-Frontend;

  ssl_certificate /etc/ssl/bundle_example.com.crt;
  ssl_certificate_key /etc/ssl/example.com_private_key.key;


  location /yoga {
    index index.php index.html index.htm;
    try_files $uri $uri/ /yoga/index.php?q=$uri&$args;

  }

  location ~ \\.php$ {
    fastcgi_split_path_info ^(/yoga)(/.*)$;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
  }
}

相关推荐

带有WordPress多站点子域的Nginx通配符SSL

我有一个保护*的通配符证书。实例com和我需要删除所有子域请求的规范www,例如:www.subdomain1。实例com=>子域1。实例com公司我复习了这个问题:https://stackoverflow.com/questions/11323735/nginx-remove-www-and-respond-to-both但他们建议的第一个服务器块是:server { server_name www.example.com; return 301 $scheme://ex