现在前后端分离没问题,想要后端也能暴露出来,可以通过域名+端口直接访问, 最好还是同一域名
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;
}
}
}