G
G
German Zvonchuk2015-10-05 16:46:55
Nginx
German Zvonchuk, 2015-10-05 16:46:55

How to make the first rule found last in NGINX?

Good evening.
I have an address domain.com/blog when accessing which I use proxy_pass to access the second server.
On the second server, I have Wordpress on blog.domain.com.
My problem is that when accessing domain.com/blog, the content is from the blog.domain.com domain, but the problem is with static files.
When accessing the address:
https://www.domain.com/blog/wp-content/themes/twen...
, the first server is accessed, I checked the access.log, but I need this request to be redirected to the second server.
As I understand this problem arose because of the rule which processes static files.
My question is: is this behavior normal?
How to make sure that absolutely all calls to https://www.domain.com/blog/* are redirected to the second server using proxy_pass?

server {
  listen 443;
  root /home/domain/www; 
  index index.php;
  server_name www.domain.com;

  location /blog {		
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://blog.domain.com:80;
  }	

  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/www;
    try_files $uri @img_proxy;
  }

  location @img_proxy {
    rewrite ^(.*)$ /index.php?$1;		
  }


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

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Fedotov, 2015-10-05
@orderbynull

last
stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI;

G
German Zvonchuk, 2015-10-06
@inside22

Alexander Fedotov the problem is that I don't use rewrite, I use proxy_pass. Where can I write LAST or BREAK here?

location /blog {		
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://blog.domain.com:80;
  }

L
Lynn "Coffee Man", 2015-10-06
@Lynn

Read documentation.
location ^~ /blog/ { ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question