首页 > 解决方案 > Apache2 到 Nginx - Laravel 7

问题描述

浏览网站时,它只是尝试下载登录页面,请协助


我的 www/website/public 文件夹中有一个 .htaccess 文件(想将其添加到我的 nginx 配置中)

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # CORS Fix
    Header set Access-Control-Allow-Origin "*"

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我有这个 nginx 配置(从 http 重定向到 https 和主站点)

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name clipdrop.io www.clipdrop.io;
    root "/var/www/website/public";
    error_log /var/www/logs/www.clipdrop.io.error.log;
    access_log /var/www/logs/www.clipdrop.io.requests.log;
    ssl_certificate /etc/apache2/ssl/clipdrop/clipdrop.crt;
    ssl_certificate_key /etc/apache2/ssl/clipdrop/clipdrop.key;
    index index.php;
    
    # serve static files directly
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
        log_not_found off;
    }

    # removes trailing slashes (prevents SEO duplicate content issues)
    if (!-d $request_filename)
    {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~* \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

主网站根目录位于 /var/www/website/ 公用文件夹位于该目录中

标签: linuxnginxapache2config

解决方案


推荐阅读