首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >角- Nginx将域/foo重写为角根,但不重写域/foo/bar。

角- Nginx将域/foo重写为角根,但不重写域/foo/bar。
EN

Stack Overflow用户
提问于 2014-12-03 20:52:15
回答 1查看 1.3K关注 0票数 0

试图使用带有Laravel后端的角JS从Apache移动到Nginx。

前端和后端完全相互独立,如var/www/角钢和var/www/laravel。它们来自相同的域--通过mysite.com/api获得的mysite.com (角)和laravel路由。

我已经完成了所有工作,包括mysite.com/foo这样的前端路由的html5mode和浏览器刷新。

问题是,刷新或手动输入mysite.com/foo/bar不起作用。相反,html是在没有css的情况下提供的,这意味着它不会被路由到角。

任何建议都是非常感谢的。

下面是我当前的Nginx配置:

代码语言:javascript
运行
复制
server {
listen 80 default_server;
server_name default;
root /home/forge/default/laravel/public;

# FORGE SSL (DO NOT REMOVE!)
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_certificate;
# ssl_certificate_key;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

index index.html index.htm index.php;

charset utf-8;

location / {
    root /home/forge/default/angular/dist;
    try_files $uri $uri/ /index.html;

}

location /lvl/ {
    try_files $uri $uri/ /index.php?$query_string;
}

location ~ \/lvl\/index\.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;

    include fastcgi_params;
    include fastcgi.conf;
    #This specifically sets so the /api/ portion
    #of the URL is not included
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    #fastcgi_param ENV production;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

access_log off;
error_log  /var/log/nginx/default-error.log error;

error_page 404 /index.html;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

location ~ /\.ht {
    deny all;
}
}

编辑1: 86的评论我尝试了一个版本的重写,他给我提供了相同的确切结果,问题仍然存在。这是我做的编辑:

代码语言:javascript
运行
复制
location / {
    root /home/forge/default/angular/dist;
    try_files = $uri @missing;
}

location @missing {
    rewrite  ^/$  /index.html  last;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-04 04:58:15

问题的根源在于,尽管我有

代码语言:javascript
运行
复制
<base href="/">

设置在我的index.html的头上

解决方案很简单..。只需将基本标签移动到头部部分的顶部,而不是底部!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27281388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档