php - Gunakan Nginx untuk membina sumber statik Typecho, semua 302 melompat ke halaman 404
我想大声告诉你
我想大声告诉你 2017-05-17 09:55:38
0
1
605

Menggunakan kaedah ini gagal/q/10...

Bukan sahaja sumber statik 302 melompat, tetapi 404.html yang melompat ke tidak boleh dimuatkan, dan php di belakang url tidak boleh dialih keluar. Tolong bantu saya menyelesaikannya! ! !

nginx konfigurasi khusus adalah seperti berikut

Port 80

server {
        listen  80;
        server_name crazyc.cn www.crazyc.cn;
        root /var/www/html/;
        #rewrite ^/(.*)$ https://crazyc.cn/index.php permanent;
        if ($ssl_protocol = "") {
            return 301 https://$server_name$request_uri;
        }
        if ($host != 'crazyc.cn' ) {
            return 301 https://crazyc.cn$request_uri;
        }
        error_log /logs/error.log;
        charset     utf-8;
        client_body_buffer_size                         512k;
        proxy_connect_timeout                           90;
        proxy_send_timeout                              90;
        proxy_read_timeout                              4000;
        proxy_buffers                                   32 4k;
        client_max_body_size 75m;
        # Load configuration files for the default server block.
        location / {
            index index.html index.php;
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php last;
            }
        }


    }
    include vhost/*;

Port 443 di bawah vhost/

server {
    listen       443 ssl;
    server_name crazyc.cn www.crazyc.cn;
    ssl on;
    ssl_certificate /root/.acme.sh/crazyc.cn/fullchain.cer;
    ssl_certificate_key /root/.acme.sh/crazyc.cn/crazyc.cn.key;
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers  HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM;
    error_log /logs/error.log;
    error_page 404 = https://crazyc.cn/404.html;
    charset     utf-8;

    client_max_body_size 75m;
        # Load configuration files for the default server block.
        location ~ .*\.php(\/.*)*$ {
            root html;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_pass  127.0.0.1:9000;
            #include fastcgi.conf;
            #fastcgi_pass  127.0.0.1:9000;
        }
        access_log logs/yourdomain.log combined;
}
我想大声告诉你
我想大声告诉你

membalas semua(1)
曾经蜡笔没有小新

Anda mempunyai terlalu banyak perkara yang dikonfigurasikan dalam port 80. Anda hanya perlu mengkonfigurasi satu perkara dalam port 80, iaitu, semua permintaan melonjak ke 443. Kemudian ubah suai konfigurasi 443 secara khusus.
Dalam 443, anda hanya menentukan akses kepada php dan tidak menyatakan laluan sumber statik. Konfigurasi rujukan adalah seperti berikut:

server {
    listen 80;
    server_name crazyc.cn www.crazyc.cn;
    rewrite ^ https://$server_name$request_uri permanent;
}

server {
    listen 443 ssl;
    server_name crazyc.cn www.crazyc.cn;
    index index.php;
    charset utf-8;
    
    ssl on;
    ssl_certificate /root/.acme.sh/crazyc.cn/fullchain.cer;
    ssl_certificate_key /root/.acme.sh/crazyc.cn/crazyc.cn.key;
    ssl_ciphers "CHACHA20:GCM:HIGH:!DH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS";
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    
    # 静态资源
    location ~* .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|apk|ttf|woff|woff2|svg|flv|swf)$ {
        add_header Access-Control-Allow-Origin *;
        root /example/path/; # 这里配你的静态资源文件根路径
    }
    
    # 以下是php配置
    location / {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include       fastcgi_params;
        try_files     $uri $uri/ /index.php?$args;
    }

Jika sumber statik anda diletakkan bersama-sama dengan fail php, akar dalam sumber statik boleh diletakkan di luar, seperti ini:

server {
    listen 80;
    server_name crazyc.cn www.crazyc.cn;
    rewrite ^ https://$server_name$request_uri permanent;
}

server {
    listen 443 ssl;
    server_name crazyc.cn www.crazyc.cn;
    root /example/path/; # 这里配你的静态资源文件根路径
    index index.php;
    charset utf-8;
    
    ssl on;
    ssl_certificate /root/.acme.sh/crazyc.cn/fullchain.cer;
    ssl_certificate_key /root/.acme.sh/crazyc.cn/crazyc.cn.key;
    ssl_ciphers "CHACHA20:GCM:HIGH:!DH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS";
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    
    # 静态资源
    location ~* .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|apk|ttf|woff|woff2|svg|flv|swf)$ {
        add_header Access-Control-Allow-Origin *;
    }
    
    # 以下是php配置
    location / {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include       fastcgi_params;
        try_files     $uri $uri/ /index.php?$args;
    }
}
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan