Web page not displayed properly , Nginx + fpm , and they are located on different servers

I have successfully installed NC13 on my ubuntu16.04 server, Every thing looks good, And I feel NC is an amazing software.

But there’s only one problem, when i use Nginx & PHP7.0-FPM, and they are located on different servers ,the web interface is wrong (Please see the screenshot, i know, it’s not configured, just example), Why is this?

But if i direct access the apache server, every thing is ok, i can finished the config by web page.

The funny thing is ,when i use Nginx & PHP7.0-FPM, The APP on android is working properly. even the web interface display is wrong.

Also,when i use simple nginx reverse proxy (not through FPM) , the web page is ok,but, The APP on android can not backup the contacts list(Other functions are normal).

You know, nginx+fpm (or nginx + php standard), and they are located on a different server models is of great significance. This model can be used to implement Intranet through…

Please help me with Web page display problem or in the FPM is not used to make Android APP backup contacts.

Hi Teng,
Usually the NGINX configuration an “upstream” PHP configuration such as this one:

    upstream php-handler {
        server 127.0.0.1:9000;
    }

And then in the server/location section, something like this:

    fastcgi_pass php-handler;

Or these could be combined:

    fastcgi_pass 127.0.0.1:9000;

This only works on the localhost. If you have a remote host you must give the IP address (or perhaps the host name). On the PHP system you need to make sure that it listens on IP address 0.0.0.0 and not on IP address 127.0.0.1 because the latter address is network adapter “lo” and it cannot be reached by other computers. You may also need to add port 9000 as a firewall exception.

I don’t know if this will solve the problem, but you didn’t really give enough information. I never tried using a remote PHP so I don’t know if it can even work.

Hope it helps.

Thanks for your reply!

Yes, you are right. This is my Nginx configure(On Nginx server,192.168.1.1):

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

And this is my www.conf(On Apache server,192.168.1.2):
listen = 9000
;listen = /run/php/php7.0-fpm.sock

if I strictly according to the official document (use FPM), the web page not displayed properly(But Android APP is OK) .But, if i use this config:

location / {
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;

proxy_pass http://192.168.1.2/; #Point the apache server, Nginx server’s ip=192.168.1.1
}

The web page will be ok, At this point, just Android APP cannot backup contacts, other functions are normal. So I think my nginx server should not be a problem.

I’ve been tested, when nginx and Apache on same server, everything is functioning correctly. So the point is, nginx and Apache on different servers(two server), you need to pay attention to what?

For me, It is not necessary to use the FPM, direct reverse proxy is acceptable because the vast majority of functions are normal, And speed is not slower than using FPM. I just don’t know why, can’t backup the contacts on the APP ( “you don’t permission…”)?

I would also like to highlight is that nginx and PHP on difrerent server, is of great general interest. This makes the NC implementation of Intranet through, Even when Nc Installed behind NAT, Right?

I think I start to understand more of what you are saying.

It seems to me that you are just using NGINX as a reverse proxy, you are not using it to generate web pages. So NGINX does not need an upstream. It is not talking to PHP-FPM. But the proxy_pass probably should use an hostname instead of an IP address. Usually Apache can be configured with multiple hostnames so whenever you talk to it you have to use hostname instead of IP address so that it knows what content to deliver.

I don’t think NGINX offers any advantages for NAT. But maybe I don’t completely understand what you are trying to do. If you want to use NC from your Android you will need to set up port forwarding. The port forwarding could be for either the NGINX or the APACHE system. If you are exposing your nextcloud server to the Internet, you should think about using HTTPS (usually port 443). But this adds some complications. It would be possible to use HTTP internally on the Apache server and just set up HTTPS on the NGINX server.

The permission problem may be due to an incomplete or incorrect proxy configuration in NGINX. You need to look at your log files.

Hi, Jonw:

Thanks for your reply.
On Github, a gettleman said it can’t remote proxy…
So, let’s focus on proxy_pass way:
In fact, this way works fine, no problems that I thought from the beginning until i find the backup contacts can go wrong. APP Tips " You do not have permission …"
This looks like a directory permissions problem , But believe me, just change to FPM way, as long as the FPM ways, the problem is gone. Also, I can back up a picture file in this Contacts folder (.Contacts…), Why?
I also install the CardDAV on my cellphone, it works fine.

Many of my friends are using NC, but as many of them are used only in a local area network, Yes ,Sometimes they maybe try remote connection by DDNS. But more and more work in this way, when in fact in this country, the computer has no internet ip (behind NAT) today.
The good news is we have a VPS, even though it is so small,we can use it as Nginx proxy server, Because it has a static internet address ,when i connect it with my NASs by VPN protocol, All problems are solved! (Remote,Domain name,SSL… ) , As for why use nginx, I can only say that it’s too popular.

I will finish config on this site,and give you more,like the log detail…

Hi, Jonw:

I’m sorry, I have other things held up for several days.
When error - backup contacts APP, I checked the logs, there was no new content.(My loglevel=>2). and my log function is ok.

Hi Jonw:

Sorry , i do not know how close this post.
I already solve my problem, it was a mistake in my Nginx config, I wrote ‘deny all’…

Thanks for everyone!

1 Like

Hi Teng,
Glad you got everything working. I have been unavailable for a few days.
Best wishes.