Vue.js Microservice子文件夹体系结构的NGINX配置文件
请容忍我,因为我没有多少配置Nginx的经验 我想创建微服务作为子文件夹。例如:www.example.com/users 用户是微服务,因此用户也将是子文件夹的名称 该网站可以托管在/var/www/html/或/var/www/html/example.com/public_html(假设这个问题是这个) 因此在主文件夹/var/www/html/example.com/public_html中有许多文件夹,每个文件夹代表一个微服务Vue.js Microservice子文件夹体系结构的NGINX配置文件,vue.js,nginx,microservices,single-page-application,nginx-location,Vue.js,Nginx,Microservices,Single Page Application,Nginx Location,请容忍我,因为我没有多少配置Nginx的经验 我想创建微服务作为子文件夹。例如:www.example.com/users 用户是微服务,因此用户也将是子文件夹的名称 该网站可以托管在/var/www/html/或/var/www/html/example.com/public_html(假设这个问题是这个) 因此在主文件夹/var/www/html/example.com/public_html中有许多文件夹,每个文件夹代表一个微服务 /var/www/html/example.com/pub
/var/www/html/example.com/public_html/users/
/var/www/html/example.com/public_html/students/
/var/www/html/example.com/public_html/teachers/
/var/www/html/example.com/public_html/parents/
每个微服务都有一个最新的文件夹,其中保存要执行的代码
/var/www/html/example.com/public_html/users/latest/
每个最新文件夹有2个文件夹-包含SPA前端代码的应用程序和包含API代码的API
/var/www/html/example.com/public_html/users/latest/app/
/var/www/html/example.com/public_html/users/latest/api/
我希望在不更改Nginx配置文件的情况下根据需要添加和删除文件夹。
如果文件夹存在,我希望显示相关的前端代码。其他404
我知道我可以根据需要在Nginx位置添加文件夹,但这不是我想要的
(不想执行以下代码)
我正在试图弄清楚是否可以将NGINX配置为基于url指向相关文件夹
这是我到目前为止,但它只是显示为404的一切,我正在努力。我正致力于用Go lang编写API,但由于我有使用PHP的经验,所以在切换到Go之前,我会先选择这条路线
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html/example.com/public_html;
index index.html;
location ^/<service>/<additional-optional-parameters-can-go-here>$ {
root /var/www/html/example.com/public_html/<service>/latest/app;
try_files $uri $uri/ =404
}
location ^/api/<service>/<additional-optional-parameters-can-go-here>$ {
root /var/www/html/example.com/public_html/<service>/latest/api;
try_files $uri $uri/ =404
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location ~ /\.ht {
deny all;
}
}
服务器{
听80;
听[:]:80;
服务器名称;
root/var/www/html/example.com/public_html;
index.html;
location^/我认为可以在location和server行中使用regex
也许这会有帮助
server_name ~^(?<subdomain>.+)\.domain\.tdl$ ~^(?<subdomain>.+)\.domain2\.tdl$ domain.tdl domain2.tdl;
location ~ ^/sitename/[0-9a-z]+/index.php$ {
fastcgi_pass phpcgi;
}
location ~ \.php$ {
return 404;
}
location ~ ^/a/b/(?<myvar>[a-zA-Z]+) {
# use variable $myvar here
if ($myvar = "sth") { ... }
}
# Example using the subdomain var created in last steps
sub_filter_once off;
sub_filter 'Site Text' '$subdomain';
sub_filter 'Site Text' '$myvar';
server\u name~^(?.+)\.domain\.tdl$~^(?.+)\.domain2\.tdl$domain.tdl domain2.tdl;
位置~^/sitename/[0-9a-z]+/index.php${
fastcgi_pass phpcgi;
}
位置~\.php${
返回404;
}
位置^/a/b/(?[a-zA-Z]+){
#在这里使用变量$myvar
如果($myvar=“sth”){…}
}
#使用在最后步骤中创建的子域变量的示例
子过滤器关闭一次;
sub_筛选器“站点文本”“$subdomain”;
子过滤器“站点文本”$myvar”;
就我个人而言,我喜欢为每个服务创建不同的conf文件,然后发布“service nginx reload”。也许您还可以自动生成conf文件。我认为您可以在位置和服务器行中使用regex
也许这会有帮助
server_name ~^(?<subdomain>.+)\.domain\.tdl$ ~^(?<subdomain>.+)\.domain2\.tdl$ domain.tdl domain2.tdl;
location ~ ^/sitename/[0-9a-z]+/index.php$ {
fastcgi_pass phpcgi;
}
location ~ \.php$ {
return 404;
}
location ~ ^/a/b/(?<myvar>[a-zA-Z]+) {
# use variable $myvar here
if ($myvar = "sth") { ... }
}
# Example using the subdomain var created in last steps
sub_filter_once off;
sub_filter 'Site Text' '$subdomain';
sub_filter 'Site Text' '$myvar';
server\u name~^(?.+)\.domain\.tdl$~^(?.+)\.domain2\.tdl$domain.tdl domain2.tdl;
位置~^/sitename/[0-9a-z]+/index.php${
fastcgi_pass phpcgi;
}
位置~\.php${
返回404;
}
位置^/a/b/(?[a-zA-Z]+){
#在这里使用变量$myvar
如果($myvar=“sth”){…}
}
#使用在最后步骤中创建的子域变量的示例
子过滤器关闭一次;
sub_筛选器“站点文本”“$subdomain”;
子过滤器“站点文本”$myvar”;
就我个人而言,我喜欢为每个服务创建不同的conf文件,然后发布“service nginx reload”。也许您还可以自动生成conf文件。以防其他人尝试类似的方法。
我上了自由职业者网站,雇了人来帮我
location ~ ^/api/([a-z]+)/.*?$ {
alias $folder_path/$1/$api_path;
rewrite ^/api/([a-z]+)/.*?$ /$1/$api_path last;
}
location ~ ^/([a-z]+)/(?:(?!\blatest\b).)*$ {
alias $folder_path/$1/$app_path;
rewrite ^/([a-z]+)/(?:(?!\blatest\b).)*$ /$1/$app_path last;
}
以防万一其他人也在尝试类似的方法。
我上了自由职业者网站,雇了人来帮我
location ~ ^/api/([a-z]+)/.*?$ {
alias $folder_path/$1/$api_path;
rewrite ^/api/([a-z]+)/.*?$ /$1/$api_path last;
}
location ~ ^/([a-z]+)/(?:(?!\blatest\b).)*$ {
alias $folder_path/$1/$app_path;
rewrite ^/([a-z]+)/(?:(?!\blatest\b).)*$ /$1/$app_path last;
}
我将尝试这种方法并在明天之前回复。这不起作用。我只是一直转到根文件夹或基本文件夹。谢谢Rahim,这让我朝着正确的方向前进。我将尝试这种方法并在明天之前回复。这不起作用。我只是一直转到根文件夹或基本文件夹。谢谢Rahim,这让我进入了正确的方向。