如何在虚拟主机(Apache)下使用 Perfect(Swift)?
Posted
技术标签:
【中文标题】如何在虚拟主机(Apache)下使用 Perfect(Swift)?【英文标题】:How to use Perfect(Swift) under a VirtualHost(Apach)? 【发布时间】:2018-07-08 00:43:39 【问题描述】:我在 Ubuntu 操作系统上安装了 Apache。我的 Ubuntu 使用亚马逊 Lightsail。我设置了一个 VirtualHost 以便像这样使用 Perfect Web 服务器
<Location "/PerfectTemplate">
ProxyPass http://localhost:8182
ProxyPassReverse http://localhost:8182
</Location>
我正在尝试从 html 进行 POST 操作,但程序引用了 Apache
var try_post_action = """
<form action="./tow" method="post">
//<form action="/tow" method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
"""
【问题讨论】:
【参考方案1】:以下Apache conf sn-p
RewriteEngine on
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule (.*) - [L,NS,H=perfect-handler]
快速文件
import PerfectHTTP
import PerfectHTTPServer
func handler(request: HTTPRequest, response: HTTPResponse)
response.setHeader(.contentType, value: "text/html")
response.appendBody(string: """
<form action="./PerfectTemplate/test" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
""")
response.completed()
let confData = [
"servers": [
[
"name":"localhost",
"port":8182,
"routes":[
["method":"get", "uri":"/", "handler":handler],
["method":"get", "uri":"/test", "handler":handler],
["method":"get", "uri":"/**", "handler":PerfectHTTPServer.HTTPHandler.staticFiles,
"documentRoot":"./webroot",
"allowResponseFilters":true]
],
"filters":[
[
"type":"response",
"priority":"high",
"name":PerfectHTTPServer.HTTPFilter.contentCompression,
]
]
]
]
]
do
try HTTPServer.launch(configurationData: confData)
catch
fatalError("\(error)")
【讨论】:
以上是关于如何在虚拟主机(Apache)下使用 Perfect(Swift)?的主要内容,如果未能解决你的问题,请参考以下文章