NGINX反向代理Apache在端口8080上运行,拥有owncloud

我有nginx作为我的主要networking服务器运行。 我已经在端口8080上安装了运行apache的owncloud。我知道owncloud对nginx有非官方的社区支持,但我更愿意保留官方的支持。

我目前的问题是,反向代理似乎没有按预期工作。 它不断加载我的默认网站。 我的网站使用灵活的HTTPS SSL证书通过cloudflare运行。

但是,我可以去xxx.xxx.xxx.xxx:8080并直接访问owncloud。

主要的nginxconfiguration

user www-data; worker_processes 2; worker_rlimit_nofile 20480; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 15; types_hash_max_size 2048; server_tokens off; # log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'; log_format main 'xx.xx.xx.xx - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "xx.xx.xx.xx"'; include /etc/nginx/mime.types; default_type application/octet-stream; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; 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; proxy_cache_path /tmp/nginx-filecache levels=1:2 keys_zone=FILES:10m inactive=7d max_size=800g; #include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } 

Nginxconfiguration为Apache

 server { listen 80; listen 443 ssl; server_name gomn.net; root /var/www/owncloud; index index.php index.htm index.html; location / { try_files $uri $uri/ /index.php; } location ~ \.php$ { proxy_pass http://localhost:8080; 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 $scheme; } location ~ /\. { deny all; } } 

这是我的apacheconfiguration为owncloud

 <VirtualHost *:8080> DocumentRoot /var/www/owncloud <FilesMatch \.php$> SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost/" </FilesMatch> <Directory /var/www/owncloud/> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /var/www/owncloud SetEnv HTTP_HOME /var/www/owncloud </Directory> <Directory /var/www/owncloud/data/*/> Allow from None Order allow,deny </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

当Nginx是你的主要networking服务器时,你为什么要使用Apache? Owncloud在Nginx上运行正常(没有Apache)。

你必须configurationNginx使用你的Apache作为上游,而不是在你的.php位置。

尝试像这样:

 upstream owncloud { server localhost:8080; } server { location / { proxypass http://owncloud; } } 

有关更多信息,请参见nginx上游文档