dongwen3437 2014-09-25 09:58
浏览 95
已采纳

在nginx上设置rutorrent和owncloud

I searched in the entire web but apparently none has published the configuration I'm looking for. I'm currently testing on a VM what I'd like to be my server config, the 3 apps I'll install are rutorrent, web interface for rtorrent, owncloud and plex, 2 of these are configured with nginx but somehow my configuration doesn't work. I created 2 virtual servers one named rutorrent, the other owncloud, my idea would be to access these with serverip/rutorrent and serverip/owncloud, separating the 2. I'm on Ubuntu 14.04, my rutorrent and owncloud folders are into /var/www, my php version is 5.5.9-1.

The current problem is that the rutorrent config works if it's the only one enabled, but it doesn't if the owncloud is enabled too, moreover, the owncloud alone doesn't work. With a stock owncloud config from their manual the owncloud works but the rutorrent returns a file not foundpage.

Here are my server files from /etc/nginx/sites-available which I have linked to the enableddirectory:

upstream php-handler {
    #server 127.0.0.1:9000;
    server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
    server_name 192.168.61.128;
    return 301 https://$server_name$request_uri;  # enforce https
}

server {
    listen 443;
    server_name 192.168.61.128;

    ssl on;
    ssl_certificate /srv/ssl/nginx.crt;
    ssl_certificate_key /srv/ssl/nginx.key;

    # Path to the root of your installation
    root /var/www;

    client_max_body_size 10G; # set max upload size
    fastcgi_buffers 64 4K;

    index index.php;
    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location /owncloud/ {
        alias /var/www/owncloud/;
        location ~ ^/owncloud/(?:\.htaccess|data|config|db_structure\.xml|README) {
                deny all;
        }

        rewrite ^/owncloud/caldav(.*)$ /owncloud/remote.php/caldav$1 redirect;
        rewrite ^/owncloud/carddav(.*)$ /owncloud/remote.php/carddav$1 redirect;
        rewrite ^/owncloud/webdav(.*)$ /owncloud/remote.php/webdav$1 redirect;

        rewrite ^/owncloud/.well-known/host-meta /owncloud/public.php?service=host-meta last;
        rewrite ^/owncloud/.well-known/host-meta.json /owncloud/public.php?service=host-meta-json last;

        rewrite ^/owncloud/.well-known/carddav /owncloud/remote.php/carddav/ redirect;
        rewrite ^/owncloud/.well-known/caldav /owncloud/remote.php/caldav/ redirect;

        rewrite ^/owncloud/apps/([^/]*)/(.*\.(css|php))$ /owncloud/index.php?app=$1&getfile=$2 last;
        rewrite ^(/owncloud/core/doc/[^\/]+/)$ $1/index.html;

        try_files $uri $uri/ index.php;

        location ~ ^/owncloud/(.+?\.php)(?:$|/) {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            set $path_info $fastcgi_path_info;
            try_files $fastcgi_script_name =404;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            #fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_INFO $path_info;
            fastcgi_param HTTPS on;
            fastcgi_param SCRIPT_NAME /owncloud/Â$fastcgi_script_name;
            fastcgi_pass php-handler;
        }
}

    # Optional: set long EXPIRES header on static assets
    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
            expires 30d;
            # Optional: Don't log access to assets
            access_log off;
    }
}

It's as close as possible to the official owncloud configuration but I get 404 error when I load the page. The rutorrent config is as follows, it has both normal and ssl config because I tried changing stuff on the normal one without touching the ssl that works:

server {
    listen 80;
    server_name 192.168.61.128;

    root /var/www;
    index index.php index.html index.htm;  

    #location / {
    #   try_files $uri $uri/ =404;
    #}

    location /rutorrent {
        auth_basic "rutorrent";
        auth_basic_user_file /var/www/rutorrent/.htpasswd;
    }

    location /RPC2 {
        include scgi_params;
        scgi_pass localhost:5000;
    }

    location ~ \.php$ {  
        fastcgi_split_path_info ^(.+\.php)(.*)$;  
        fastcgi_pass   unix:/var/run/php5-fpm.sock;  
        fastcgi_index  index.php;
        include fastcgi.conf;
        #fastcgi_intercept_errors        on;  
        #fastcgi_ignore_client_abort     off;  
        #fastcgi_connect_timeout 60;  
        #fastcgi_send_timeout 180;  
        #fastcgi_read_timeout 180;  
        #fastcgi_buffer_size 128k;  
        #fastcgi_buffers 4 256k;  
        #fastcgi_busy_buffers_size 256k;  
        #fastcgi_temp_file_write_size 256k;  
    }

    location ~ /\.ht {  
        deny  all;  
    }
}

server {
    listen 443;
    server_name 192.168.61.128;

    root /var/www;
    index index.php index.html index.htm;

    ssl on;
    ssl_certificate     /srv/ssl/nginx.crt; #server.crt
    ssl_certificate_key /srv/ssl/nginx.key; #server.key

    ssl_session_timeout 5m;

    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
    ssl_prefer_server_ciphers on;

    location / {
        #try_files $uri $uri/ =404;
    }

    location /rutorrent {
        auth_basic "rutorrent";
        auth_basic_user_file /var/www/rutorrent/.htpasswd;
    }

    location ~  \.php$ {  
        fastcgi_split_path_info ^(.+\.php)(.*)$;  
        fastcgi_pass unix:/var/run/php5-fpm.sock;  
        fastcgi_index index.php;
        include fastcgi.conf;
        #fastcgi_intercept_errors on;  
        #fastcgi_ignore_client_abort off;  
        #fastcgi_connect_timeout 60;  
        #fastcgi_send_timeout 180;  
        #fastcgi_read_timeout 180;  
        #fastcgi_buffer_size 128k;  
        #fastcgi_buffers 4 256k;  
        #fastcgi_busy_buffers_size 256k;  
        #fastcgi_temp_file_write_size 256k;  
    }

    location /RPC2 {
        include scgi_params;
        scgi_pass localhost:5000;
    }

    location ~ /\.ht {  
        deny  all;  
    }
}

And finally my nginx.conf which again is as close as standard as possible.

user www-data;
    worker_processes 4;
    pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log info;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

I'm quite bad with this stuff, but intuitively it shouldn't be this hard. Thanks for the help.

  • 写回答

2条回答 默认 最新

  • dsjws44266 2014-09-26 08:14
    关注

    There's a lot with this config that could be improved, but your primary issue is that define two server blocks with identical server_name. They won't be merged, if that's what you're expecting, but one is picked, the other isn't.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!