G
G
German Zvonchuk2015-08-13 13:13:20
linux
German Zvonchuk, 2015-08-13 13:13:20

Nginx - how to move the domain.com/blog/ URL to a separate directory?

Good afternoon colleagues.
I have one site, domain.com which is located at /home/domain.com/www
everything works fine.
Now it's time to create a blog for this site.
I created /home/domain.com.blog/www and now I'm trying to set up NGINX to work with this folder.
Created a rule:

location /blog {
  
  root /home/domain.com.blog/www;
  index index.php;
  
  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }
}

Wordpress started to load, but static files were not loaded, I had to add a separate one correctly for static files.
location /blog {
  
  root /home/domain.com.blog/www;
  index index.php;
  
  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }
  
  location ~* \.(gif|jpg|jpeg|png|ico|bmp|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|woff|exe|eot|svg|ttf)$ {
    root /home/domain.com.blog/www;
    expires 14d;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    access_log off;
  }
}

After that, static files started loading, the last problem that I could not overcome was links.
https://domain.com/blog/2015/08/05/hello-world/
I would be very grateful if you tell me how to make Wordpress links work.
Here is the error.log
2015/08/13 15:10:59 [error] 1127#0: *53 "/home/domain.com.blog/www/blog/2015/08/05/hello-world/index.php" is not found (2: No such file or directory), client: 81.21.83.210, server: domain.com, request: "GET /blog/2015/08/05/hello-world/ HTTP/1.1", host: "domain.com"

I want to note that Wordpress is installed in the directory: home/domain.com.blog/www/blog/
The only thing that confuses me in error.log is where index.php comes from at the end of the URL
server {
    listen 443;
    root /home/domain.com/www;
    index index.php; 
    server_name domain.com;
  
  location ~* \.(gif|jpg|jpeg|png|ico|bmp|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|woff|exe|eot|svg|ttf)$ {
    root /home/domain.com/www;
    expires 14d;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    access_log off;
    log_not_found off;
  }
  
  
  location /admin {
    try_files $uri $uri/ /admin/index.php?/$request_uri;
        }

  location / {
    try_files $uri $uri/ /index.php?/$request_uri;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }
}

I would be very grateful if you tell me how to get Wordpress on NGINX in a sub-directory.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2015-08-13
@Arik

The only thing that confuses me in error.log is where index.php comes from at the end of the URL

From here
Try location /blog add try_files with wordpress rules. - there are a lot of articles.
There is simply no rule that if there is no file, then what address to trace to try

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question