现在前后端分离没问题,想要后端也能暴露出来,可以通过域名+端口直接访问, 最好还是同一域名
server
{
listen 80;
server_name www.xxx.cc;
index index.html index.htm;
set $base_path "/xxx/xxx/xx";
root "${base_path}";
location / {
alias "${base_path}/dist/";
index index.html index.htm;
try_files $uri $uri/ /index.html$is_args$args;
}
location /api/ {
proxy_pass http://127.0.0.1:9222/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 9222;
server_name 127.0.0.1 www.xxx.cc;
location / {
root /xxx/xxx/xx;
index index.php;
try_files $uri $uri/ $uri/index.php$is_args$args;
location ~ ^(.+?\.php)($|/.*) {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9005;
fastcgi_index index.php;
}
}
}
1
gaogang 2022-08-21 10:12:58 +08:00
|
2
securityCoding 2022-08-21 11:32:39 +08:00
|
3
whale 2022-08-21 11:52:49 +08:00
www.xxx.cc/api 不就是后端地址了,不知道是出于什么考虑加的第二个 server ,准备放二级域名 api.xxx.cc ?
|
4
kestrelBright OP @whale 之前试过这种,会出现 file not found
··· server { listen 80; server_name www.xxx.cc; index index.html index.htm; set $base_path "/xxx/xxx/xx"; root "${base_path}"; location / { alias "${base_path}/dist/"; index index.html index.htm; try_files $uri $uri/ /index.html$is_args$args; } location /api/ { rewrite ^/api/(.+)$ $1; root /xxx/xxx/xx; index index.php; try_files $uri $uri/ $uri/index.php$is_args$args; location ~ ^(.+?\.php)($|/.*) { include fastcgi.conf; fastcgi_pass 127.0.0.1:9005; fastcgi_index index.php; } } } ··· |
5
kestrelBright OP @gaogang 访问不到,会 file not found
|
6
skys215 2022-08-21 12:41:16 +08:00
@kestrelBright 看 nginx 去访问了哪个路径就知道哪里配置不对了
|
7
kestrelBright OP @skys215 看 access 日志 路径是对的
|
8
kestrelBright OP 卧槽。。。现在重启 nginx 后 又行了。。。
|