在LNMP服务器上部署Laravel项目----nginx的配置文件

在此之前我们已经上传laravel项目到对应的服务器文件夹并且用composer安装了对应的扩展包了。在LNMP服务器上部署Laravel项目,步骤如下:

  1. 将域名解析到你的LNMP服务器;
  2. 打开php的cgi.fix_pathinfo配置,在php.ini文件下寻找cgi.fix_pathinfo,将其值设置为1;
  3. 修改对应的域名nginx.conf配置文件(修改如下):
server {
        listen 80; # 监听端口
	server_name www.xxx.com  # 指定解析的域名
        root  /home/wwwroot/www.xxx.com/public; # 网站的根目录,laravel要指定到网站根目录下面的public文件夹
	
        location / {
            index index.html index.htm index.php;
            try_files $uri $uri/ /index.php?$query_string; # 这一句是laravel部署必须的,将index.php隐藏掉
        }
        # 这一段是解析php文件的引导,模拟PATH_INFO的模式
        location ~ \.php(.*)$ {
            fastcgi_pass   unix:/tmp/php-cgi.sock;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log off;
    }

猜你喜欢

转载自blog.csdn.net/u014447599/article/details/80489522