Config nginx for Laravel In a subfolder

后端 未结 7 699
失恋的感觉
失恋的感觉 2020-12-14 18:28

I have and old project that now requires new functionality, I\'m going to use laravel to provide it, everything in working ok in xampp with apache but my server con nginx sh

7条回答
  •  独厮守ぢ
    2020-12-14 19:18

    please use this :

    server {
    client_body_in_file_only clean;
    client_body_buffer_size 32K;
    
    client_max_body_size 300M;
    
    sendfile on;
    send_timeout 300s;
    # Port that the web server will listen on.
    #listen          80;
    
    # Host that will serve this project.
    server_name     tsolar.com;
    
    # Useful logs for debug.
    access_log      /var/log/nginx/tsolar.com-access.log;
    error_log       /var/log/nginx/tsolar.com-error.log;
    rewrite_log     on;
    
    # The location of our projects public directory.
    root            /home/tom/public_html/demos/;
    
    # Point index to the Laravel front controller.
    index           index.php;
    
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
    }
    
    location / {
    
        # URLs to attempt, including pretty ones.
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }
    
    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
        rewrite     ^/(.+)/$ /$1 permanent;
    }
    
    # version 1
    location ^~ /demo1 {
        alias /home/tom/public_html/demos/demo1/public;
        try_files $uri $uri/ @demo1;
    
        location ~* \.php {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            include /etc/nginx/fastcgi_params;
        }
    }
    
    location @demo1 {
        rewrite ^/demo1/(.*)$ /demo1/index.php/$1 last; # THIS IS THE IMPORTANT LINE
    }
    # end version 1
    
    # version 2
    # this is with `ln -s /home/tom/public_html/demos/demo1/public /demo1`
    location ~ /demo1 {
        try_files /demo1/$uri /demo1/$uri/ /demo1/index.php?q=$uri&$args;
    }
    # end version 2
    
    
    # PHP FPM configuration.
    location ~* \.php$ {
        fastcgi_pass                    unix:/var/run/php5-fpm.sock;
        include                             /etc/nginx/fastcgi_params;
        fastcgi_index                       index.php;
        fastcgi_split_path_info             ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO             $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED       $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME       $document_root$fastcgi_script_name;
    }
    
    # We don't need .ht files with nginx.
    location ~ /\.ht {
        deny all;
    }
    
    # Set header expirations on per-project basis
    location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
        expires 365d;
    }
    

    }

提交回复
热议问题