We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
由 What’s the difference between the “mainline” and “stable” branches of nginx? 这篇文章可知,尽量下载最新版的 mainline 版本,而不是 stable 版本。
.\nginx.exe -t
start .\nginx.exe
.\nginx.exe -s stop
参考资料:run nginx as windows service
.\nssm.exe install
Path
D:\Software\nginx-1.17.9\nginx.exe
Startup directory
D:\Software\nginx-1.17.9
I/O
Input
Output
Error
d:\Software\nginx-1.17.9\logs\access.log
d:\Software\nginx-1.17.9\logs\error.log
Install service
.\nssm.exe start nginx
vue-cli 打包后的页面,在用 IIS 代理的情况下,会随机出现页面请求无法到达服务器的情况。因为请求无法到达服务器,所以在日志中也看不出什么问题。
为了保证页面的可用性,只好临时安装配置上 Nginx,让 Nginx 代理页面,IIS 负责将请求转发给 Nginx。
查看 Nginx 官网的 Windows 安装程序版本,和其它系统的版本是一样的,那就可以放心使用了。
cd
logs
.\nginx.exe -s reload
nginx auto start windows
服务器上有几个页面在 Nginx 及 IIS 中配置之后,通过域名访问总是有问题。后来直接访问 Nginx 代理的页面,发现同样有问题,这个时候才知道并不是 Nginx 没有匹配上路径,而是代码本身就不完善,后面还需要进一步调整。
nginx location always match root path
vue-router 开启了 history 模式时,就会有这个问题;如果不开启,就没有这个问题了。
history
vue-router 不开启 history 模式时,URL 中 # 后面的部分不会发往服务端,Nginx 官方文档也有说明,location 指令只能匹配 URL 中域名之后的第一个斜杠 / 与第一个问号 ? 或第一个井号 # 之间的部分。
#
location
/
?
vue-router 为组件设置路径为 path: '/msg/:msg?',组件中通过 beforeRouteUpdate() 方法监听路由的变化。Nginx 中的代理如下设置:
path: '/msg/:msg?'
beforeRouteUpdate()
location /msg/ { alias e:/upcweb/vue-router/dist/; try_files $uri $uri/ /index.html; }
在浏览器中访问 http://localhost:9999/msg/ 时,会自动转为访问 http://localhost:9999/msg/#/ 这个页面,对应于上面项目的根组件。需要以 http://localhost:9999/msg/#/msg/123/ 这种形式,才能访问到指定组件设置的路径。
http://localhost:9999/msg/
http://localhost:9999/msg/#/
http://localhost:9999/msg/#/msg/123/
nginx location match special character
vue-router 开启了 history 模式之后,照着下面的方式配置过,访问 http://localhost:9999/msg/123/ 这样的路径都会匹配到 Nginx 中设置的 location /,而不是按照期望中的匹配到路由中的动态部分:
http://localhost:9999/msg/123/
location /
vue-router nginx 配置 -404
以列表形式记录本次需求实现过程中的要点:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
精简流程
下载最新版 Nginx
由 What’s the difference between the “mainline” and “stable” branches of nginx? 这篇文章可知,尽量下载最新版的 mainline 版本,而不是 stable 版本。
测试运行
.\nginx.exe -t
测试配置文件是否可用start .\nginx.exe
启动 nginx,并查看 nginx 代理的页面是否可正常访问.\nginx.exe -s stop
,停止 nginx 程序NSSM 持久化运行
参考资料:run nginx as windows service
.\nssm.exe install
,会出现 NSSM 图形化安装界面Path
参数指向 nginx 最新版程序的位置,如D:\Software\nginx-1.17.9\nginx.exe
Startup directory
参数指向 nginx 所在文件夹,如D:\Software\nginx-1.17.9
I/O
标签下的Input
,设置为start .\nginx.exe
I/O
标签下的Output
和Error
,设置为 nginx 访问成功和访问失败的日志文件,如d:\Software\nginx-1.17.9\logs\access.log
和d:\Software\nginx-1.17.9\logs\error.log
Install service
,安装服务,成功后会有提示.\nssm.exe start nginx
,将 nginx 服务运行起来,然后访问 nginx 所代理的页面,如果正常显示,说明 nginx 服务已配置成功,done!需求描述
vue-cli 打包后的页面,在用 IIS 代理的情况下,会随机出现页面请求无法到达服务器的情况。因为请求无法到达服务器,所以在日志中也看不出什么问题。
为了保证页面的可用性,只好临时安装配置上 Nginx,让 Nginx 代理页面,IIS 负责将请求转发给 Nginx。
方案调研
调研过程
查看 Nginx 官网的 Windows 安装程序版本,和其它系统的版本是一样的,那就可以放心使用了。
入选方案
应用过程
Windows 下运行
cd
至 exe 所在目录之后,执行start .\nginx.exe
。一个新的命令行窗口会一闪而过,访问 localhost:80 能够显示 Nginx 相关页面,说明已经配置成功。logs
子文件夹中,需要在配置文件中开启记录日志的选项。.\nginx.exe -s reload
。.\nginx.exe -t
。参考资料
Windows 下保活
nginx auto start windows
路径匹配不上的问题
服务器上有几个页面在 Nginx 及 IIS 中配置之后,通过域名访问总是有问题。后来直接访问 Nginx 代理的页面,发现同样有问题,这个时候才知道并不是 Nginx 没有匹配上路径,而是代码本身就不完善,后面还需要进一步调整。
参考资料
nginx location always match root path
打包版本不能附加路径
vue-router 开启了
history
模式时,就会有这个问题;如果不开启,就没有这个问题了。vue-router 不开启
history
模式时,URL 中#
后面的部分不会发往服务端,Nginx 官方文档也有说明,location
指令只能匹配 URL 中域名之后的第一个斜杠/
与第一个问号?
或第一个井号#
之间的部分。vue-router 为组件设置路径为
path: '/msg/:msg?'
,组件中通过beforeRouteUpdate()
方法监听路由的变化。Nginx 中的代理如下设置:在浏览器中访问
http://localhost:9999/msg/
时,会自动转为访问http://localhost:9999/msg/#/
这个页面,对应于上面项目的根组件。需要以http://localhost:9999/msg/#/msg/123/
这种形式,才能访问到指定组件设置的路径。nginx location match special character
vue-router 开启了
history
模式之后,照着下面的方式配置过,访问http://localhost:9999/msg/123/
这样的路径都会匹配到 Nginx 中设置的location /
,而不是按照期望中的匹配到路由中的动态部分:vue-router nginx 配置 -404
参考资料
要点总结
以列表形式记录本次需求实现过程中的要点:
The text was updated successfully, but these errors were encountered: