I set up 2 nginx webserver from this tutorial https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing-with-ssl-termination
The problem is, a simple one test php page via SSL is loaded nicely, but when I try to install some PHP Application like Moodle, I got mixed content warning and the UI is broken.. (some in HTTP mode, some in HTTPS mode, etc...)
How can I get all content loaded in all HTTPS (fix the mixed content thing)?
Here is the frontend SSL Nginx config:
# File: \etc\nginx\sites-available\main.big.vm
upstream mainBigVm {
server main.big.vm:80;
}
server {
listen 80;
listen 443 ssl;
ssl on;
ssl_certificate /etc/nginx/cert.crt;
ssl_certificate_key /etc/nginx/cert.key;
server_name main.big.vm;
location / {
proxy_pass http://mainBigVm;
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;
}
}
And here is the backend Nginx config (in server main.big.vm):
# File: \etc\nginx\sites-available\default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html index.php;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5217-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
update 170430-1
I've tried the suggested config in front-end, but still not work.
upstream mainBigVm {
server main.big.vm:80;
}
#suggestion
server {
listen 80;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 80;
listen 443 ssl;
ssl on;
ssl_certificate /etc/nginx/cert.crt;
ssl_certificate_key /etc/nginx/cert.key;
server_name main.big.vm;
location / {
proxy_pass http://mainBigVm;
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;
}
}
update 170501-1
I noticed a strange behavior too. If I type the HTTPS URL with ending slash, the URL is loaded, but if I type without the ending slash, somehow the URL is converted to HTTP with auto added end-slash