下面由laravel教程欄目給大家介紹nginx配置站點 ,希望對需要的朋友有所幫助!
前言
設置laravel項目的域名站點的時候,需要對nginx做一些對應的重寫rewrite配置,用來做相關路由,否則會報404。
nginx.conf配置
server { listen 80; server_name xxx.com; #域名 root /data/www/myProject/blog/public; #站點目錄,請求到laravel項目的public目錄 index index.html index.htm index.php; #默認請求的文件 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location / { try_files $uri $uri/ /index.php?$query_string; # 這一句是laravel部署必須的,將index.php隱藏掉 } if (!-d $request_filename) { rewrite ^/(.+)/$ /$1 permanent; } # 去除index action if ($request_uri ~* index/?$) { rewrite ^/(.*)/index/?$ /$1 permanent; } # 根據laravel規則進行url重寫 if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?/$1 last; break; } location = /50x.html { root html; } }
操作及實例
1.對nginx.conf重寫站點后,要重啟nginx:
sudo nginx -s reload
2.以laravel5.2版本為例,模擬輸出hello world,可以在laravel項目中app/http/routes.php中定義一個hello的路由:
Route::get('/hello', function(){ return 'hello world'; });
3.瀏覽器輸入xxx.com/hello即可在瀏覽器打印出hello world
推薦:最新的五個Laravel視頻教程
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END
喜歡就支持一下吧
相關推薦