M
M
Mishman72019-10-02 16:42:44
Nginx
Mishman7, 2019-10-02 16:42:44

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;

   }         
}

Everything is working.
TASK:
Put wordpress next to it. Wordpress set to var/www/mysite/mysite_rest/wp
Added to config:
#    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;
}

Result: URL example.com/wp is rewritten as https://example.comindex.php/wp-admin/install.php
With uncommented internal - 404. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-10-02
@dodo512

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

M
Mishman7, 2019-10-03
@Mishman7

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

BUT THEREFORE , rewrite ^/(.*)/$ /$1 permanent;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question