在 nginx 上设置 rutorrent 和 owncloud

Posted

技术标签:

【中文标题】在 nginx 上设置 rutorrent 和 owncloud【英文标题】:Setting up rutorrent and owncloud on nginx 【发布时间】:2014-09-25 09:58:47 【问题描述】:

我搜索了整个网络,但显然没有人发布我正在寻找的配置。 我目前正在VM上测试我想成为我的服务器配置的3个应用程序,我将安装的3个应用程序是rutorrent,rtorrent的Web界面,owncloud和plex,其中2个配置了nginx但不知何故我的配置没有不行。我创建了 2 个虚拟服务器,一个名为 rutorrent,另一个名为 owncloud,我的想法是使用 serverip/r​​utorrent 和 serverip/owncloud 访问这些服务器,将两者分开。我在 Ubuntu 14.04 上,我的 rutorrent 和 owncloud 文件夹位于 /var/www ,我的php版本是5.5.9-1。

当前的问题是,如果仅启用了 rutorrent 配置,则它可以正常工作,但如果也启用了 owncloud 则不会,此外,单独的 owncloud 不起作用。使用他们手册中的股票 owncloud 配置,owncloud 可以工作,但 rutorrent 返回 file not foundpage。

这是来自/etc/nginx/sites-available 的服务器文件,我已链接到enabled 目录:

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;
    

它尽可能接近官方的owncloud配置,但我在加载页面时收到404错误。 rutorrent 配置如下,它既有普通配置,也有 ssl 配置,因为我尝试在普通配置上更改内容而不触及有效的 ssl:

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;  
    

最后是我的nginx.conf,它再次尽可能接近标准。

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/*;

我对这些东西很不满意,但直觉上它不应该这么难。感谢您的帮助。

【问题讨论】:

【参考方案1】:

您完全正确,我修改了将两个位置放在同一个虚拟主机中的配置,这是一个工作结果,再次主要改编自 OwnCloud 手册。

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;

    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

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

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

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

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

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

        rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;

        try_files $uri $uri/ index.php;        
    

    location ~ ^/(data|config|\.ht|db_structure\.xml|README) 
        deny all;
    

    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 HTTPS on;;
        fastcgi_pass php-handler;
    

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

    location /RPC2 
        include scgi_params;
        scgi_pass unix:/home/rtorrent/.sockets/scgi.socket;
    

    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ 
        expires 30d;
        access_log off;
    

【讨论】:

【参考方案2】:

这个配置有很多可以改进的地方,但你的主要问题是定义两个具有相同 server_name 的服务器块。它们不会被合并,如果这是您所期望的,但会选择一个,另一个不会。

【讨论】:

以上是关于在 nginx 上设置 rutorrent 和 owncloud的主要内容,如果未能解决你的问题,请参考以下文章

iptorrent的auto-irssi设置

设置好 NGINX 反向代理后,如何在引入 NGINX 反向代理的 NGINX 上配置 SSL 直通? [复制]

在 mamp 免费版上使用 nginx 设置 vhost

如何在Ubuntu上通过Nginx设置HTTP认证

WEB服务与NGINX-NGINX的I/O模型

如何在 Nginx 中为 Janus REST api 和 socket api 设置反向代理?