如何配置Nginx以仅为Azure应用服务上的wordpress提供https

z3yyvxxp  于 2023-01-29  发布在  Nginx
关注(0)|答案(1)|浏览(142)

我一直在处理Azure应用程序服务,以服务WordPress使用的是nginx,这里是目前的nginx配置,我正在使用,但它给了我多个“通过HTTPS加载,但要求一个不安全的脚本”错误,任何想法如何解决这个问题?

upstream php {
    server unix:/tmp/php-cgi.socket;
    server 127.0.0.1:9000;
}

server {
    #proxy_cache cache;
    #proxy_cache_valid 200 1s;
    listen 8080;
    listen [::]:8080;
    root /home/site/wwwroot;
    index  index.php index.html index.htm;
    server_name  server.com; 
    port_in_redirect off;
    
    access_log   /home/data/access.log;
    error_log    /home/data/error.log;



    # Custom to allow large file uploads
    
    client_max_body_size 256M;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /html/;
    }

    # Disable .git directory
    location ~ /\.git {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Add locations of phpmyadmin here.
    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_connect_timeout         300; 
        fastcgi_send_timeout           3600; 
        fastcgi_read_timeout           3600;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }

    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

    location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$is_args$args =404;
    }
    

    if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
    }

    location ~ \.php$ {
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            include fastcgi_params;
            fastcgi_intercept_errors on;
            fastcgi_pass php;
            #The following parameter can be also included in fastcgi_params file
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }

}

我尝试了nginx和wordpress页面上的多个配置。(没有一个工作完全是给予我错误404和太多的重定向。

bnlyeluc

bnlyeluc1#

<?php
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';

我添加了这个到wp配置加上nginx的一部分,使其工作在azure应用服务

相关问题