使用 IIS 10 设置 Laravel 5.4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45464267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setup laravel 5.4 with IIS 10
提问by Anders
I want to deploy laravel projects on our IIS 10, running on windows server 2016. What is the easiest and still secure way to do that?
我想在我们的 IIS 10 上部署 Laravel 项目,在 Windows Server 2016 上运行。最简单且仍然安全的方法是什么?
回答by Anders
This is how I did it; I'm not sure it is the right way.
我就是这样做的;我不确定这是正确的方法。
- Install URL Rewrite module (https://www.iis.net/downloads/microsoft/url-rewrite)
- Put repo in some folder E:/sites/helloworld
- In IIS add a virtual directory called "helloworld" pointing to E:/sites/helloworld/public
- Make sure folders bootstrap/cache and storage is open for writing.
- Dont forget to make env file.
In your web.php route file put:
Route::get('/', function () { return view('welcome'); }); Route::get('/also', function () { return view('welcome'); });
- 安装 URL 重写模块 ( https://www.iis.net/downloads/microsoft/url-rewrite)
- 将 repo 放在某个文件夹 E:/sites/helloworld
- 在 IIS 中添加一个名为“helloworld”的虚拟目录,指向 E:/sites/helloworld/public
- 确保文件夹引导程序/缓存和存储打开以进行写入。
- 不要忘记制作 env 文件。
在您的 web.php 路由文件中放置:
Route::get('/', function () { return view('welcome'); }); Route::get('/also', function () { return view('welcome'); });
Add the file web.config in public dir and paste the rules:
在公共目录中添加文件 web.config 并粘贴规则:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You should now be able to access both URLs meaning laravel routing works as intended. If you try another non-existent route you will get a laravel exception.
您现在应该能够访问两个 URL,这意味着 Laravel 路由按预期工作。如果您尝试另一条不存在的路线,您将获得 laravel 异常。