Angular20 nginx安装,angular项目部署
1 nginx安装(Windows版本)
1.1 下载安装包
到官网下载Windows版本的nginx安装包
技巧01:下载好的压缩包解压即可,无需安装

1.2 启动nginx
进入到解压目录,点击 nginx.exe 就可以启动nginx啦

1.3 验证
打开浏览器,跳转到 http://127.0.0.1/ 后如果出现下面的页面就说明nginx安装成功啦

1.4 参考文档
2 angular项目部署
2.1 项目打包
对angular项目进行打包处理,打包好后在angular项目的根目录会出现一个dist文件夹,该文件夹存放的就是打包好的项目文件

技巧01:需要到 package.json 中去修改 ng build 指令

{
"name": "qcbx",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod --base-href /qcbx/",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.5",
"@angular/cdk": "^5.2.2",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/material": "^5.2.2",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "~1.7.0",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}
2.2 打包项目移动
将打包好的项目移动到任意位置,例如:

2.3 nginx配置
nginx需要配置的东西也就是在conf文件中,打开安装目录下的 conf/nginx.conf 在http节点下添加server节点

技巧01:天假server节点时一定要加上 try_files $uri $uri/ /index.html; 否则项目配置的子路由无法生效

#user nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} server {
listen 8888;
server_name localhost;
location / {
root "G:/dev/angular/dist";
index index.html;
try_files $uri $uri/ /index.html;
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
2.4 重启nginx
技巧01:利用命令启动或者关闭nginx时必须进入到安装nginx的根目录,例如

Windows下nginx命令操作:点击前往
nginx.exe
nginx.exe -s stop
nginx.exe -s quit
nginx.exe -s reload
坑01:重启nginx后还必须清楚浏览器数据,再访问时才可以看到最新的效果,否则会是重启nginx之前的效果
2.5 效果展示
利用浏览器访问 http://127.0.0.1:8888/ 就会弹出angular项目的页面

2.6 参考文档
Angular20 nginx安装,angular项目部署的更多相关文章
- Angular4---部署---将Angular项目部署到IIS上
---恢复内容开始--- Angular项目部署到一个IIS服务器上 1.安装URL rewrite组件: 网址:https://www.microsoft.com/en-us/download/de ...
- [转]Angular4---部署---将Angular项目部署到IIS上
本文转自:https://www.cnblogs.com/kingkangstudy/p/7699710.html Angular项目部署到一个IIS服务器上 1.安装URL rewrite组件: 网 ...
- .NET Core +Angular 项目 部署到CentOS
前言: 最近公司需要开发项目能在Linux系统上运行,示例开发项目采用.Net Core + Angular开发:理论上完全支持跨平台. 但是实践才是检验真理的唯一标准:那么还是动手来验证实现下:过程 ...
- 基于腾讯云CentOS7.4+MySQL5.7+Python3+uwsgi+nginx的Django项目部署
准备知识 1.django一个基于python的开源web框架,请确保自己熟悉它的框架目录结构. 2.uWSGI一个基于自有的uwsgi协议.wsgi协议和http服务协议的web网关 3.nginx ...
- Linux下tomcat的安装与项目部署
最近在linux下安装了jdk,为了圆我以前的心愿,把tomcat也安装了,顺便部署个项目,也算是小又成就感 废话不说了,直接上过程 一.下载安装对应的jdk,并配置Java环境. 有关jdk的安装请 ...
- centos 5.8 x64Jetty的安装以及项目部署配置
链接地址:http://blog.csdn.net/shuixin536/article/details/9049821 安装环境 centos 5.8 x64 安装前须知 首先在安装Jetty之前要 ...
- 微服务架构 ------ DockerCompose从安装到项目部署
DockerCompose的目的:简化Docker的启动和停止流程,以及编排Docker启动服务与服务之间的关系 DockerCompose的安装:curl -L https://get.daoclo ...
- Nginx+Uwsgi+Django 项目部署到服务器。
首先先说一下思路: 1.本地django项目打包 主要用到的是 python自带的distutils.core 下的 setup,具体代码在下面,主要讲的两个问题是package主要打包为和目录同级的 ...
- tomcat安装与项目部署
1.tomcat依赖:jdk jre,环境变量配置 java_home jre_home 2.tomcat安装: 下载:http://tomcat.apache.org/ download ...
随机推荐
- 立即掌握SSM框架的要诀
ssm框架的总结: 1. 首先是POM.xml 文件的配置,他的作用主要是添加依懒的关系和自动下载相关的包. 2.对jdbc.properties进行配置 ,作用就是连接你的数据库的配置. 3.对接着 ...
- dedecms幻灯片调用图片模糊的解决办法
dedecms幻灯片调用的是缩略图,如果图片尺寸比例和幻灯片的大小相差太大的话,图片就会自动拉伸模糊,比较影响美观和用户体验,下面就有常用的2个方法来解决这个图片模糊的问题. 第一种:手动制图 我们用 ...
- 织梦DedeCms获取当前页面URL地址的调用方法
织梦内容页如何调用当前页面url?相信很多对织梦感兴趣的朋友都会去考虑这个问题:在文章内容中加入本文链接,除了 保护自己版权外还可以增加网站的外链收录.网上这方面的帖子一搜一大堆,但多数都只能调用相对 ...
- 话说TP框架里的Vendor这目录是干什么用的啊?类库扩展thinkphp3.1版本
类库扩展包括基类库扩展.应用类库扩展和第三方类库扩展,所有扩展类库不会自动加载,需要手动加载或者定义别名和配置自动加载(详细可以参考4.2.3类库导入和4.2.5自动加载). 1 基类库扩展 目前支持 ...
- Core Graphics 和Quartz 2D的区别
quartz是一个通用的术语,用于描述在IOS和MAC OS X中整个媒体层用到的多种技术 包括图形.动画.音频.适配. Quart 2D 是一组二位绘图和渲染API,Core Graphic会使用 ...
- 【编程技巧】ExtJs 设置GridPanel表格文本垂直居中
详细讲解见 http://blog.csdn.net/li396864285/article/details/9310983 以下是我改修的代码: { width:90, ...
- Vue.js学习网址
Vue官网:http://cn.vuejs.org/v2/guide/index.html 淘宝镜像:http://npm.taobao.org/ Vue-router:https://router. ...
- SpringMvc4.x---快捷的ViewController
@RequestMapping("/index") public String hello(){ return "index"; } 此处无任何的业务处理,只是 ...
- git fetch, git pull 剖析
真正理解 git fetch, git pull 要讲清楚git fetch,git pull,必须要附加讲清楚git remote,git merge .远程repo, branch . commi ...
- 在 Tomcat 上配置虚拟主机
.Tomcat 服务器的server.xml文件 (1)Tomcat 组件 Tomcat服务器是由一系列可配置的组件构成,其中核心组件是 Catalina Servlet 容器,它是所有其他 To ...