Apakah yang berlaku apabila nginx sentiasa memuat turun fail dan tidak boleh membuka halaman web apabila mengakses localhost?
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 17:14:59
0
3
836

Lalai dalam fail yang tersedia tapak nginx telah mengubah suai laluan akar. Tetapi apabila mengakses localhost, ia sentiasa memuat turun halaman web secara langsung dan bukannya membuka URL, yang sangat pelik.

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html/laravel/public;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;

    server_name 127.0.0.1;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
过去多啦不再A梦
过去多啦不再A梦

membalas semua(3)
巴扎黑

Melihat konfigurasi soalan, terdapat laravel, ia seolah-olah berkaitan dengan PHP, maka penanya, anda harus memuat turun php5-fpm dahulu, kerana nginx sendiri tidak melaksanakan program PHP seperti Apache, tetapi. memberikannya kepada pelaksanaan php5-fpm.

Jadi, langkah anda hendaklah seperti berikut:

  • Muat turun php5-fpm

  • Konfigurasikan nginx untuk berkomunikasi dengan fpm Terdapat banyak kaedah konfigurasi di Internet. socket.fpm dan nginx. Konfigurasikan kaedah komunikasi yang sama!!

  • Sama ada ujian akhir berjaya? Sudah tentu, halaman yang diakses akan dimuat turun apabila anda tiba di sini, anda perlu menyelesaikan masalah sekali lagi, tetapi lebih selamat untuk penyoal mendapatkan fpm pertama.

Untuk menyelesaikan masalah subjek dengan lebih baik, saya menyimpan salinan konfigurasi yang baru saya buat dalam persekitaran ubuntu14.04

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/html;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;    
        #}

        #error_page 404 /404.html;

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

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        ## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

                # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

Tidak banyak perubahan:

  • index Saya meletakkan index.php di kedudukan pertama

  • laluan akar, sila ambil perhatian bahawa laluan terakhir tidak mempunyai / /

  • 去掉跟php有关的注释,我在fpm的 /etc/php5/fpm/pool.d/www.conf中找到listen = /var/run/php5-fpm.sock,说明fpm是开启了socket,所以nginx的fastcgi_pass

Alih keluar ulasan yang berkaitan dengan php, saya dapati listen = /var/run/php5-fpm dalam /etc/php5/fpm/pool.d/www.conf fpm /code>, menunjukkan bahawa fpm telah mendayakan soket, jadi parameter fastcgi_pass nginx juga ialah soket.🎜🎜 🎜
仅有的幸福

Sebagai contoh, pada akhir php, anda perlu menggunakan cgi php untuk menghuraikannya

小葫芦
#location ~ \.php$ {
#    include snippets/fastcgi-php.conf;
#
#    # With php7.0-cgi alone:
#    fastcgi_pass 127.0.0.1:9000;
#    # With php7.0-fpm:
#    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny all;
#}
这串代码我取消注释 nginx restart 会报错

@chenjiayao

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!