nginx config file for Joomla 3.4 host


I'm trying to host my Joomla 3.4 website in virtualmin server by nginx. I'm using SSL as default for my self and want to redirect http to https.

Here is my config file in /etc/nginx/sites-available

server {
return 301 https://$host$request_uri;
server_name_in_redirect off;

root /home/jplay/public_html;
index index.php index.html index.htm default.html default.htm;
access_log /var/log/virtualmin/jplay.tv_access_log;
error_log /var/log/virtualmin/jplay.tv_error_log;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME /home/jplay/public_html$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT /home/jplay/public_html;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;

location / {
expires 1d;

    # Enable joomla SEF URL's inside Nginx
    try_files $uri $uri/ /index.php?$args;

# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
                return 403;
                error_page 403 /403_error.html;

location ~ \.php$ {
            fastcgi_pass unix:/var/php-nginx/143979903845399.sock/socket;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;

# caching of files
location ~* \.(ico|pdf|flv)$ {
                expires 1y;

    location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
                expires 14d;

# ssl on;
listen default_server ssl;
fastcgi_read_timeout 120;
ssl_certificate /home/jplay/ssl.cert;
ssl_certificate_key /home/jplay/ssl.key;

} is the private IP, I changed to public IP or 80 but it didn't work. It always show:

This webpage has a redirect loop


Port config:



It works correctly when I use 2 separate blocks. Thank you.