我试图通过nginx配置实现这一目标:
mydomain.com/api should serve the php API
mydomain.com/login should serve an angular 2 app
mydomain.com/dashboard should serve another angular 2 app
我发布的nginx.conf工作正常,除了这个(这是我需要帮助修复的问题):
当用户以 mydomain.com/dashboard/forms 之类的角度访问路线时,网址会被重写为 mydomain.com/dashboard/dist/forms < / p>
这是代码树:
├── mydomain.com
│ ├── app // slim project
│ │ └── ...
│ ├── public
│ │ ├── dashboard // anuglar project
| | | └── dist
│ │ └── login // angular project
| | └── dist
这是我使用的服务器块:
server {
listen 80;
server_name mydomain.com;
error_log /home/test/code/mydomain.com/error.log;
access_log /home/test/code/mydomain.com/access.log;
root /home/test/code/mydomain.com/public/;
sendfile on;
rewrite_log on;
include /etc/nginx/mime.types;
gzip on;
location ~ ^/(assets|bower_components|scripts|styles|views) {
expires 31d;
add_header Cache-Control public;
}
############################################################################
# D A S H B O A R D
############################################################################
location /dashboard/ {
alias /home/test/code/mydomain.com/public/dashboard/dist/;
try_files $uri $uri/ /index.html =404;
}
############################################################################
# L O G I N
############################################################################
location /login/ {
alias /home/test/code/mydomain.com/public/login/dist/;
try_files $uri $uri/ /index.html =404;
}
############################################################################
# A P I
############################################################################
location ~ ^/api/(.*)$ {
alias /home/test/code/mydomain.com/public;
try_files $1 $1/ @php;
index index.php;
}
location @php {
fastcgi_split_path_info ^(/api)(/.*)$;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/test/code/mydomain.com/public/index.php;
fastcgi_param REQUEST_URI $fastcgi_path_info;
fastcgi_read_timeout 900;
}
}
我应该改变什么以便&#34; / dist&#34;没有写在网址上?
答案 0 :(得分:1)
配置文件实际上很好。问题是使用--base-ref / dashboard / dist /而不是plain / dashboard /
构建角度应用程序