(*正如一些评论建议,我删除了index.ejs并在项目中使用index.html遵循this answer.所以我调整了我的OP *)
我在Mac上用apache开发了一个可以请求的MEAN-stack应用程序
https://开头本地主机:3000 /#/家.在使用Nginx服务器进行生产时,可以请求应用程序
https://www.myapp.io/#/home.由于角度ui-router,在所有情况下都需要片段标识符#.
所以我想在没有#(例如,https://www.myapp.io/home,https:// localhost:3000 / home)的情况下制作漂亮的网址.我做了以下事情:
1)添加$locationProvider.html5Mode(true); app.config中的$locationProvider.hashPrefix(”)([‘$stateProvider’….
2)添加< base href =“/”/>在index.html中
因此,https:// localhost:3000 /#/ home会自动更改为浏览器栏中的https:// localhost:3000 / home,类似于https://www.myapp.io/#/home.
但是,在浏览器中直接输入https:// localhost:3000 / home或https://www.myapp.io/home会引发错误(我不知道如何转换前一个< h1><%=消息%>< / h1>< h2><%= error.status%>< / h2>< pre><%= error.stack%>< / pre>错误. ejs到error.html,所以我没有更多细节).
所以现在,目标是使https:// localhost:3000 / home和https://www.myapp.io/home工作.
按照this thread,我在app.js中添加了以下内容:
app.use('/js',express.static(__dirname + '/js'));
app.use('/dist',express.static(__dirname + '/../dist'));
app.use('/css',express.static(__dirname + '/css'));
app.use('/partials',express.static(__dirname + '/partials'));
app.all('/*',function(req,res,next) {
res.sendFile('index.html',{ root: __dirname });
});
在mac的apache中,这是我的httpd-vhosts.conf,重启apache之后,
https:// localhost:3000 / home仍然返回错误.
在生产中,这是Nginx服务器块.重新启动Nginx后,https://www.myapp.io/home仍然会返回错误.
server {
listen 443 ssl;
server_name myapp.io www.myapp.io;
ssl_certificate /etc/letsencrypt/live/myapp.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myapp.io/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:EC$
ssl_session_timeout 1d;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;
index index.html;
root /opt/myapp
location / {
try_files $uri $uri/ /index.html;
}
location ~ /.well-known {
allow all;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Accept-Encoding "";
proxy_set_header Proxy "";
proxy_pass https://127.0.0.1:3000;
# These three lines added as per https://github.com/socketio/socket.io/issues/1942 to remove sock$
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
有人可以帮忙吗?
一旦你理解了这一点,你可能会成功获得GitHub上angular-ui的官方配置建议.