-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from zeabur/pan93412/zea-1202-add-official-su…
…pport-for-acg-faka
- Loading branch information
Showing
9 changed files
with
177 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
server { | ||
listen 8080; | ||
root /var/www/public; | ||
|
||
add_header X-Frame-Options "SAMEORIGIN"; | ||
add_header X-Content-Type-Options "nosniff"; | ||
|
||
index index.php index.html; | ||
charset utf-8; | ||
|
||
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$ { | ||
try_files $uri =404; | ||
fastcgi_split_path_info ^(.+\.php)(/.+)$; | ||
fastcgi_pass 127.0.0.1:9000; | ||
fastcgi_index index.php; | ||
include fastcgi_params; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
fastcgi_param PATH_INFO $fastcgi_path_info; | ||
fastcgi_buffering off; | ||
} | ||
|
||
location / { | ||
if (!-e $request_filename){ | ||
rewrite ^(.*)$ /index.php?s=$1 last; break; | ||
} | ||
} | ||
|
||
location ~ /\.(?!well-known).* { | ||
deny all; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package php | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/zeabur/zbpack/pkg/types" | ||
) | ||
|
||
//go:embed nginx-conf | ||
var nginxConfFs embed.FS | ||
|
||
// RetrieveNginxConf retrieves the nginx conf for the given app. | ||
// | ||
// The app should be an instance of types.PHPApplication; otherwise, | ||
// an error will be returned. | ||
func RetrieveNginxConf(app string) (string, error) { | ||
appConfMap := map[string]string{ | ||
string(types.PHPApplicationDefault): "nginx-conf/default.conf", | ||
string(types.PHPApplicationAcgFaka): "nginx-conf/acg-faka.conf", | ||
} | ||
|
||
filename, ok := appConfMap[app] | ||
if !ok { | ||
return "", fmt.Errorf("unknown app: %s", app) | ||
} | ||
|
||
f, err := nginxConfFs.Open(filename) | ||
if err != nil { | ||
return "", fmt.Errorf("open: %w", err) | ||
} | ||
|
||
nginxConfBytes, err := io.ReadAll(f) | ||
if err != nil { | ||
return "", fmt.Errorf("readall: %w", err) | ||
} | ||
nginxConf := string(nginxConfBytes) | ||
|
||
return escape(nginxConf), nil | ||
} | ||
|
||
func escape(s string) string { | ||
s = strings.ReplaceAll(s, "\n", "\\n") | ||
s = strings.ReplaceAll(s, "$", "\\$") | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package php | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/zeabur/zbpack/pkg/types" | ||
) | ||
|
||
func TestEscape(t *testing.T) { | ||
assert.Equal(t, escape("a\nb"), "a\\nb") | ||
assert.Equal(t, escape("a$b"), "a\\$b") | ||
} | ||
|
||
func TestRetrieveNginxConf_Default(t *testing.T) { | ||
conf, err := RetrieveNginxConf(string(types.PHPApplicationDefault)) | ||
|
||
assert.NoError(t, err) | ||
assert.Contains(t, conf, escape("try_files $uri $uri/ /index.php?$query_string;")) | ||
} | ||
|
||
func TestRetrieveNginxConf_AcgFaka(t *testing.T) { | ||
conf, err := RetrieveNginxConf(string(types.PHPApplicationAcgFaka)) | ||
|
||
assert.NoError(t, err) | ||
assert.Contains(t, conf, escape("rewrite ^(.*)$ /index.php?s=$1 last; break;")) | ||
} | ||
|
||
func TestRetrieveNginxConf_Unknown(t *testing.T) { | ||
_, err := RetrieveNginxConf("unknown") | ||
|
||
assert.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters