إعادة توجيه YOURLS لا تعمل في NGINX - تنزيلات الملفات بدلاً من ذلك

StackOverflow https://stackoverflow.com//questions/25082696

  •  02-01-2020
  •  | 
  •  

سؤال

أحاول تكوين لك لموقعي.لقد قمت بتكوين المضيف الظاهري في nginx الخاص بي ويعمل التطبيق الرئيسي بشكل جيد تمامًا.ولكن عند النقر على عنوان URL قصير، فبدلاً من إعادة التوجيه إلى عنوان URL الحقيقي، يتم تنزيل الملف فعليًا.

أرى أن المشكلة كلها تتعلق بملف التكوين nginx، لأن النظام نفسه كان يعمل بشكل جيد مع Apache.

هذا هو ملف التكوين nginx الخاص بي:

server {
    listen   80; ## listen for ipv4; this line is default and implied
#   listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/evry.st/;
    index index.html index.htm index.php;

    # Make site accessible from http://localhost/
    server_name evry.st;

    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.php;
         if (!-e $request_filename){
    rewrite ^(.*)$ /?$1 break;
  }

        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    # Only for nginx-naxsi : process denied requests
    #location /RequestDenied {
        # For example, return an error code
        #return 418;
    #}

    #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/www;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~* \.php$ {
         ## FastCGI microcache.
        #include microcache_fcgi.conf;
        #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;

        fastcgi_buffer_size 128k;
        fastcgi_buffers 16 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
            fastcgi_intercept_errors on;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}
هل كانت مفيدة؟

المحلول

YOURLS لا يوجد لديه /index.php.التكيف الخاص بك try_files بيان للقراءة:

try_files $uri $uri/ /yourls-loader.php;

يجب أن يكون هذا غير ضروري ويمكن إزالته:

if (!-e $request_filename){
    rewrite ^(.*)$ /?$1 break;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top