Answer the question
In order to leave comments, you need to log in
How to configure nginx wordpress next to an existing site?
Need your help with nginx config.
There is:
example.com/api/* - requests go to the file /var/www/mysite/mysite_rest/api/index.php?url=* , and are executed on the php side, via php-fpm
example.com/* - we try find file in folder /var/www/mysite/mysite_rest only html page
As configured:
server {
listen 80;
server_name example.com;
# return 301 https://$host$request_uri;
return 301 https://example.com;
rewrite ^ https://example.com$request_uri? permanent;
client_max_body_size 350M;
}
server {
listen 443 ssl http2;
server_name example.com;
charset UTF-8;
##
rewrite ^/(.*)/$ /$1 permanent;
rewrite ^/api/(.*)$ /api/index.php?_url=/$1 last;
rewrite ^/api$ /api/index.php?_url=/ last;
##
location / {
root /var/www/mysite/mysite_rest;
charset utf-8;
index index.php index.html;
}
location /api {
internal;
root /var/www/mysite/mysite_rest/api;
index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/var/run/php7.1-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_FILENAME /var/www/mysite/mysite_rest/api/index.php;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_param HTTPS on;
# fastcgi_param HTTP_HTTPS on;
fastcgi_param REQUEST_SCHEME https;
fastcgi_param SERVER_PORT 443;
}
}
# location /wp {
internal;
root /var/www/mysite/wp;
index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/var/run/php7.1-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_FILENAME /var/www/mysite/wp/index.php;
fastcgi_param SCRIPT_NAME index.php;
# fastcgi_param HTTPS on;
fastcgi_param HTTP_HTTPS on;
fastcgi_param REQUEST_SCHEME https;
fastcgi_param SERVER_PORT 443;
}
Answer the question
In order to leave comments, you need to log in
location /wp {
root /var/www/mysite;
try_files $uri /wp/index.php?args;
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
}
}
As a result, the working location in my case:
location ^~ /wp {
root /var/www/mysite/mysite_rest;
index index.php index.html index.htm;
try_files $uri $uri/ /wp/index.php;
location ~ \.php {
fastcgi_split_path_info ^(.*\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question