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 |1 Answer
Reset to default 0I 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;
}
}
location /news
block seems off to me. Why is/news
used fortry_files
as well? And does the sub-location block really work like that? – kero Commented Dec 18, 2019 at 15:45