laravel10.x nginx service recommended configuration file

laravel10.x server configuration

If you are deploying your application to a server running Nginx, you can use the following configuration file as a starting point for configuring your web server. Most likely, this file needs to be customized according to the server's configuration. If you want help with managing your server, consider using a first-party Laravel server management and deployment service such as Laravel Forge.

Make sure, like the configuration below, that your web server directs all requests to the application's public/index.php file. You should never attempt to move the index.php file to the project root, as serving the application from the project root will expose many sensitive configuration files to the public internet

insert image description here

server {
    
    
    listen 80;
    listen [::]:80;
    server_name example.com;
    root /srv/example.com/public;
 
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
 
    index index.php;
 
    charset utf-8;
 
    location / {
    
    
        try_files $uri $uri/ /index.php?$query_string;
    }
 
    location = /favicon.ico {
    
     access_log off; log_not_found off; }
    location = /robots.txt  {
    
     access_log off; log_not_found off; }
 
    error_page 404 /index.php;
 
    location ~ \.php$ {
    
    
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
 
    location ~ /\.(?!well-known).* {
    
    
        deny all;
    }
}

Easy deployment with Forge / Vapor

Laravel Forge

If you're not quite ready to manage your own server configuration, or are unwilling to configure all the various services required to run a robust Laravel application, Laravel Forge is a great option.

Laravel Forge can create servers on various infrastructure providers such as DigitalOcean, Linode, and AWS. Additionally, Forge installs and manages all the tools needed to build a powerful Laravel application, such as Nginx, MySQL, Redis, Memcached, Beanstalk, and more.

Laravel Vapor

If you want a fully serverless, auto-scaling deployment platform, check out Laravel Vapor. Laravel Vapor is a serverless deployment platform for Laravel, powered by AWS. Launch your Laravel infrastructure on Vapor and fall in love with the scalable simplicity of serverless. The creators of Laravel have fine-tuned Laravel Vapor to work seamlessly with the framework so that you can continue writing Laravel applications as before.

Guess you like

Origin blog.csdn.net/itopit/article/details/131864479
Recommended