Nginx服务器不支持Symlink并给出:文件未找到(Laravel项目)

pzfprimi  于 2023-08-03  发布在  Nginx
关注(0)|答案(1)|浏览(105)

我的内容目录是:/home/ubuntu/domain.name/laravel_server/code我的www-web目录是:/var/www/domain.name/html
创建从内容到www-web的符号链接
sudo ln -s /home/ubuntu/domain.name/laravel_server/code /var/www/domain.name/html
现在这个目录/var/www/domain.name/html显示/home/ubuntu/domain.name/laravel_server/code的内容
但nginx不阅读内容,给我文件找不到

server {

    index index.php;
    
    server_name domain.name www.domain.name;
    
    root /var/www/domain.name/html/public/;
    
    error_log /var/log/nginx/error.log;
    access_log  /var/log/nginx/access.log;
    
    location / {
        autoindex on;
        autoindex_exact_size on;
        disable_symlinks off;
        index  index.nginx-debian.html index.html index.php;
        try_files $uri $uri/ /index.php$is_args$args;
        root /var/www/domain.name/html/public/;
    }
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_buffering off;
        fastcgi_buffer_size 2M;
        fastcgi_buffers 8 2M;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
    location ~ /\.ht {
        deny  all;
    }
    
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain.name/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain.name/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.domain.name) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = domain.name) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    
    
    listen 80;
    
    server_name domain.name www.domain.name;
    return 404; # managed by Certbot

}

个字符
enter image description here

我的网站应该与符号链接内容。

mum43rcc

mum43rcc1#

你已经禁用了使用disable_symlinks off;的符号链接,你也不应该在location块中使用root指令,除非绝对必要。
更新你的Nginx配置,看起来像这样:

server {

    root /var/www/domain.name/html/public/;
    index index.php;

    server_name domain.name www.domain.name;

    error_log /var/log/nginx/error.log;
    access_log  /var/log/nginx/access.log;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain.name/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain.name/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.domain.name) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = domain.name) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;

    server_name domain.name www.domain.name;
    return 404; # managed by Certbot

}

字符串
记住在修改配置文件后重新启动或重新加载Nginx。此外,请确保符号链接权限正确。

相关问题