最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nginx - How to install WordPress on sub directory in ubuntu 16.4 in same vhost with AngularJS

programmeradmin3浏览0评论

I have vhost for the main domain www.example. and I want to install WordPress in a subdirectory called news (www.example/news/).

This is the vhost configuration file.

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

server {
  listen 80;
  server_name example www.example;
  return 301 $request_uri;
}

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

  ssl_certificate /etc/ssl/bundle_example.crt;
  ssl_certificate_key /etc/ssl/example_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;
    }
  }
}

Problem: once I enter www.example/news/, it always redirect to www.example.

I have vhost for the main domain www.example. and I want to install WordPress in a subdirectory called news (www.example/news/).

This is the vhost configuration file.

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

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

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

  ssl_certificate /etc/ssl/bundle_example.crt;
  ssl_certificate_key /etc/ssl/example_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;
    }
  }
}

Problem: once I enter www.example/news/, it always redirect to www.example.

Share Improve this question asked Dec 18, 2019 at 15:40 Lim SocheatLim Socheat 101 2
  • This is not really WordPress specific (as WP doesn't even get loaded). You might have better luck on ServerFault or StackOverflow. Besides that: Your location /news block seems off to me. Why is /news used for try_files as well? And does the sub-location block really work like that? – kero Commented Dec 18, 2019 at 15:45
  • Because of the root block is for Angular only serve HTML and /news block need to run PHP. – Lim Socheat Commented Dec 18, 2019 at 15:49
Add a comment  | 

1 Answer 1

Reset to default 0

I found the answer

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

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

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

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

  ssl_certificate /etc/ssl/bundle_example.crt;
  ssl_certificate_key /etc/ssl/example_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;
  }
}
发布评论

评论列表(0)

  1. 暂无评论