2014-02-09 42 views
1

我想代理我的nginx服務器(樹莓派 - 它有自己的雲)到我的本地apache,它也安裝了自己的雲。問題是,我可以到達index.php,但圖片的GET加載永遠不會到達代理。 pi allways在他的根源尋找他們。nginx代理傳遞到本地cms/owncloud服務器

配置nginx的覆盆子

server { 
listen 443 ssl; # Make it listen on port 443 for SSL, on both IPv4 and IPv6 interfaces 
server_name lexxxel.no-ip.org; 

root /var/www/; # Make sure to insert proper path for your ownCloud root directory 

index index.php; 
client_max_body_size 10G; 


# Now we configure SSL certificates. Make sure you enter correct path for your SSL cert files 
ssl_certificate /etc/nginx/certs/server.crt; 
ssl_certificate_key /etc/nginx/certs/server.key; 

fastcgi_buffers 128 4K; 

# Configure proper error pages 
error_page 403 = /core/templates/403.php; 
error_page 404 = /core/templates/404.php; 

# Protecting sensitive files from the evil outside world 
location ~ ^/(data|config|\.ht|db_structure.xml|README) { 
    access_log off; 
    log_not_found off; 
    deny all; 
} 

location/{ 
    auth_basic "Please enter your acc and password"; 
    auth_basic_user_file /var/www/.htpasswd; 
} 

location /manji/ { 
     auth_basic off; 
    #proxy_cache_key "$host$request_uri$cookie_user"; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Forwarded-Proto https; 
    proxy_pass https://192.168.178.22/manji/; 
    #proxy_redirect default; 
} 

# Configure the root location with proper rewrite rule 
location /owncloud/ { 

# Some rewrite rules, more to come later 
rewrite ^/caldav((/|$).*)$ /remote.php/caldav$1 last; 
rewrite ^/carddav((/|$).*)$ /remote.php/carddav$1 last; 
rewrite ^/webdav((/|$).*)$ /remote.php/webdav$1 last; 


    auth_basic off; 
    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 ^/apps/calendar/caldav.php /remote.php/caldav/ last; 
    rewrite ^/apps/contacts/carddav.php /remote.php/carddav/ last; 
    rewrite ^/apps/([^/]*)/(.*\.(css|php))$ /index.php?app=$1&getfile=$2 last; 
    rewrite ^(/core/doc[^\/]+/)$ $1/index.html; 

    index index.php; # This one might be redundant, but it doesn't hurt to leave it here 
    fastcgi_read_timeout 10m; 
    try_files $uri $uri/ index.php; 
} 

location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ { 
    try_files $script_name = 404; 

    include fastcgi_params; 
    fastcgi_param PATH_INFO $path_info; 
    fastcgi_param HTTPS on; 
    fastcgi_read_timeout 3600s; 
    # This one is a little bit tricky, you need to pass all parameters in a single line, separating them with newline (\n) 
    fastcgi_param PHP_VALUE "upload_max_filesize = 10G \n post_max_size = 10G"; # This finishes the max upload size settings 
    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # On some systems OC will work without this setting, but it doesn't hurt to leave it here 

    fastcgi_pass unix:/var/run/php5-fpm.sock; 
} 

location ~* ^.+.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ { 
    expires 365d; 
    access_log off; 
    fastcgi_read_timeout 10m; 
} 

location /svn { 
    access_log off; 
    proxy_pass https://localhost:444; 
} 

# location /phpmyadmin { 
# access_log off; 
# proxy_pass https://localhost:444; 
# allow 1.1.1.1; 
# #deny all; 
# include /etc/nginx/proxy_params; 
# location ~* ^.+\.php$ { 
#  proxy_pass https://localhost:444; 
#  include /etc/nginx/proxy_params; 
# } 
# location ~* ^.+.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ { 
#  proxy_pass https://localhost:444; 
#  include /etc/nginx/proxy_params; 
# } 
# } 

location ~ ^/home/valerio/(owncloud/)?data { 
    internal; 
    root /; 
} 

location ~ ^/tmp/oc-noclean/.+$ { 
    internal; 
    root /; 
} 

location ~ ^\.(htaccess|htpasswd)$ { 
    deny all; 
} 
} 

nginx的error.log中說是這樣的:

2014/02/09 19:03:38 [error] 24752#0: *289 open() "/var/www404" failed (2: No such file or directory), client: 192.168.178.30, server: 192.168.178.11, request: "GET /manji/owncloud/index.php/apps/files/css/upload.css?v=74b4d273507a7e0eba857955bd45b2cf HTTP/1.1", host: "192.168.178.11", referrer: "https://192.168.178.11/manji/owncloud/" 

我認爲

location /manji/ { 

是問題,但我現在發現解決方案(如果使用proxy_pass,則禁止^ ^)

如果我寫

location ~^ /manji/ { 

我得到

sudo service nginx reload 
Reloading nginx configuration: nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/sites-enabled/owncloud:99 

nginx的:配置文件/etc/nginx/nginx.conf測試失敗

回答

0

請問你的Apache下供應owncloud實例/ manji上下文?

如果是 - 並且apache負責處理* php文件 - 爲什麼需要在nginx中處理php文件的位置?

除了location/manji/之外,每個位置的評論都排在第一位,並嘗試一下。這條規則應該處理你所有的流量到你自己的雲實例。

server { 
listen 443 ssl; # Make it listen on port 443 for SSL, on both IPv4 and IPv6 interfaces 
server_name lexxxel.no-ip.org; 

root /var/www/; # Make sure to insert proper path for your ownCloud root directory 

index index.php; 
client_max_body_size 10G; 


# Now we configure SSL certificates. Make sure you enter correct path for your SSL cert files 
ssl_certificate /etc/nginx/certs/server.crt; 
ssl_certificate_key /etc/nginx/certs/server.key; 

fastcgi_buffers 128 4K; 

# Configure proper error pages 
error_page 403 = /core/templates/403.php; 
error_page 404 = /core/templates/404.php; 

# Protecting sensitive files from the evil outside world 
location ~ ^/(data|config|\.ht|db_structure.xml|README) { 
    access_log off; 
    log_not_found off; 
    deny all; 
} 

location/{ 
    auth_basic "Please enter your acc and password"; 
    auth_basic_user_file /var/www/.htpasswd; 
} 

location /manji/ { 
     auth_basic off; 
    #proxy_cache_key "$host$request_uri$cookie_user"; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Forwarded-Proto https; 
    proxy_pass https://192.168.178.22/manji/; 
    #proxy_redirect default; 
} 


location /svn { 
    access_log off; 
    proxy_pass https://localhost:444; 
} 



location ~ ^/home/valerio/(owncloud/)?data { 
    internal; 
    root /; 
} 

location ~ ^/tmp/oc-noclean/.+$ { 
    internal; 
    root /; 
} 

location ~ ^\.(htaccess|htpasswd)$ { 
    deny all; 
} 
}