Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have to admit I am completely new to WebServers and now try to figure out how to configure my nginx (for home-purpose). I have already running a web-service rutorrent on my nginx with the default structure. Now I wanna change the dir structure into:

/usr/share/nginx/html/        (should contain the default-config)
/usr/share/nginx/rtorr_dir/   (should contain the rutorrent-content)

My aim is: On my browser I wanna enter 192.168.0.2/rutorrent and this should automatically access on the rtorr_dir. I tried the following:

server {
        listen *:80;

    access_log  /var/log/nginx/access.log info;
    error_log   /var/log/nginx/error.log debug;
    auth_basic      "ruser";
    auth_basic_user_file    /etc/users.htpasswd;

        location /rutorrent {
          rewrite /rutorrent/(.*) /$1 break;
          root /usr/share/nginx/rtorr_dir;
          index index.php index.html;
        }

        location /RPC1 {
          include /etc/nginx/scgi_params;
          scgi_pass backend2;
        }
        location ~  \.php$ {
          fastcgi_split_path_info ^(.+\.php)(.*)$;
          fastcgi_pass   backend;
        ....

I tried as well location / and other variations but obviously not the proper ones :(. So my question would be

  • How to set up the rewrite properly?
  • What is the change, when the root has already some part of the url included? (e.g. rtorr_dir)
  • Do I need to change for the other locations as well something, or is this taken automatically for the underlying files (i.e. php)?
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can use alias directive in your use case. Ref: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

So,

location /rutorrent {
  alias /usr/share/nginx/rtorr_dir;
}

Should work. You may still need index and directives.

Do I need to change for the other locations as well something, or is this taken automatically for the underlying files (i.e. php)?

Since, you use multiple locations, I'd recommend using location ~* \.php$ { on each of those locations. For example...

location /rutorrent {
  alias /usr/share/nginx/rtorr_dir;
  try_files $uri $uri/ /index.php;

  location ~* \.php$ {
    # directives to process PHP
  }
}

location /another_random_location {
  alias /usr/share/nginx/another_random_directory;
  try_files $uri $uri/ /index.php;

  location ~* \.php$ {
    # directives to process PHP
  }
}

If you keep a PHP location block alongside other location blocks, then that PHP block would only get it's path from the root directive set for the server block. The safest way is to include the PHP location block on each location that needs to process PHP.

I hope that helps.

share|improve this answer
    
Thx for the hint. Especially thx for the complete sample, cause only the first half wouldn't have made it. And also thx for the PHP tip. You made my day :) –  LeO Oct 4 '13 at 12:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.