安装和启动

  1. Mac上搭建nginx教程

通过Homebrew 安装nginx brew install nginx

  1. 配置

    添加配置文件在 /usr/local/etc/nginx/servers 目录下 ( 一般都是修改 /usr/local/etc/nginx 目录下nginx.conf 文件, 后来发现nginx.conf 下有 include servers/*; 为了方便管理我本地项目,就把本地项目配置都放到 /usr/local/etc/nginx/servers 目录下 )
  • nginx相关配置在 /usr/local/etc/nginx/目录下
  • nginx配置文件为 nginx.conf 以及 nginx.conf.default
  • nginx.conf配置 把 server 和其他基本配置分开。其中server相关配置全部放置在config.d文件夹中,其他配置依旧防止在nginx.conf中

附 文末:本地nginx测试服务器配置

  1. 启动

    在终端中输入 ps -ef|grep nginx

    如果执行的结果是
501 15800 1 0 12:17上午 ?? 0:00.00 nginx: master process /usr/local/Cellar/nginx/1.8.0/bin/nginx -c /usr/local/etc/nginx/nginx.conf
501 15801 15800 0 12:17上午 ?? 0:00.00 nginx: worker process
501 15848 15716 0 12:21上午 ttys000 0:00.00 grep nginx

表示已启动成功,如果不是上图结果,在终端中执行

/usr/local/Cellar/nginx/1.8.0/bin/nginx -c /usr/local/etc/nginx/nginx.conf

命令即可启动nginx。 
这时候如果成功访问localhost:8080,说明成功安装和启动好了。

⚠️ 启动前确认,8080 端口未占用

  1. 停止

在终端中输入 ps -ef|grep nginx 获取到nginx的进程号,注意是找到“nginx:master”的那个进程号,如下面的进程好是 15800

501 15800 1 0 12:17上午 ?? 0:00.00 nginx: master process /usr/local/Cellar/nginx/1.8.0/bin/nginx -c /usr/local/etc/nginx/nginx.conf
501 15801 15800 0 12:17上午 ?? 0:00.00 nginx: worker process
501 15848 15716 0 12:21上午 ttys000 0:00.00 grep nginx

在终端中输入以下几种命令都可以停止

kill -QUIT 15800 (从容的停止,即不会立刻停止)

Kill -TERM 15800 (立刻停止)

Kill -INT 15800 (和上面一样,也是立刻停止)

  1. 重启

如果配置文件错误,则将启动失败,所以在启动nginx之前,需要先验证在配置文件的正确性 nginx -t -c /usr/local/etc/nginx/nginx.conf,如下表示配置文件正确

  /usr/local/Cellar/nginx/1.8.0/bin/nginx -t -c /usr/local/etc/nginx/nginx.conf
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

重启有两种方法 :

  • 在终端输入输入如下命令即可重启
  cd /usr/local/Cellar/nginx/1.8.0/bin/
./nginx -s reload
  • 根据进程号重启,执行命令 kill -HUP [进程号]

实用使用命令

启动:sudo nginx

停止:sudo nginx -s stop

验证:sudo nginx -t /usr/local/nginx/conf/nginx.conf

跳坑报错指南

  1. 在Mac上用brew安装Nginx,然后修改Nginx配置文件,再重启时报出如下错误:

    nginx: [error] invalid PID number “” in “/usr/local/var/run/nginx/nginx.pid”

    解决办法:
$ sudo nginx -c /usr/local/etc/nginx/nginx.conf
$ sudo nginx -s reload

本地nginx测试服务器配置

项目根目录为开发项目下构建后dist, api 为 接口api

 server {
listen 8090; #监听端口 可以访问127.0.0.1:8090
# server_name test.com; #这里要是使用需要配本地的host #charset koi8-r;
access_log logs/k8s.log; location = / {
root /Users/macbookpro/Downloads/workspace/node-web/dist; #你项目的根目录
index index.html index.htm;
} location /api/ {
proxy_pass https://api.baidu.com; #****这里配置nginx代理,填上服务器地址
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

前端开发--nginx篇的更多相关文章

  1. 前端开发--nginx番外篇

    Centos7下Nginx开发使用(背景: 阿里云ECS Centos7) 安装和启动 安装教程 Centos7安装Nginx实战 需要主意的如下: 文中第四步 4.配置编译参数命令:(可以使用./c ...

  2. 网站前端开发--css篇

    Ⅰ 全局:global.css 全局样式为全站公用,为页面样式基础,页面中必须包含. 结构:layout.css 页面结构类型复杂,并且公用类型较多时使用.多用在首页级页面和产品类页面中. 私有:st ...

  3. 前端开发--Mongodb篇

    安装和启动 安装 官方安装文档 本地mac Os推荐使用Homebrew ⚠️ 目前直接使用--brew install mongodb-- 安装 mongodb 时提示:Error: No avai ...

  4. openresty 前端开发入门五之Mysql篇

    openresty 前端开发入门五之Mysql篇 这章主要演示怎么通过lua连接mysql,并根据用户输入的name从mysql获取数据,并返回给用户 操作mysql主要用到了lua-resty-my ...

  5. 1. web前端开发分享-css,js入门篇

    关注前端这么多年,没有大的成就,就入门期间积累了不少技巧与心得,跟大家分享一下,不一定都适合每个人,毕竟人与人的教育背景与成长环境心理活动都有差别,但就别人的心得再结合自己的特点,然后探索适合自己的学 ...

  6. 2. web前端开发分享-css,js进阶篇

    一,css进阶篇: 等css哪些事儿看了两三遍之后,需要对看过的知识综合应用,这时候需要大量的实践经验, 简单的想法:把qq首页全屏另存为jpg然后通过ps工具切图结合css转换成html,有无从下手 ...

  7. 旨在脱离后端环境的前端开发套件 - IDT Server篇

    IDT,一个基于Nodejs的,旨在脱离后端环境的前端开发套件,目的就是能让前端开发完全脱离后端的环境,无论后端是什么模板引擎(主流),都能应付自如. IDT主要包括两大部分:Server + Bui ...

  8. 旨在脱离后端环境的前端开发套件 - IDT之Server篇

    IDT,一个基于Nodejs的,旨在脱离后端环境的前端开发套件,目的就是能让前端开发完全脱离后端的环境,无论后端是什么模板引擎(主流),都能应付自如. IDT主要包括两大部分:Server + Bui ...

  9. web前端开发分享-css,js入门篇(转)

    转自:http://www.cnblogs.com/jikey/p/3600308.html 关注前端这么多年,没有大的成就,就入门期间积累了不少技巧与心得,跟大家分享一下,不一定都适合每个人,毕竟人 ...

随机推荐

  1. Rearrangement

    In a two dimensional array of integers of size 2×n2 \times n2×n, is it possible to rearrange integer ...

  2. log4j2.xml 配置

    动态生成日志, 日志路径: log4j2.xml 配置如下: <?xml version="1.0" encoding="UTF-8"?> < ...

  3. ByteCode Instrumentation

    Bytecode Instrumentation 定义 我们首先来看看,什么叫"Instrumentation"?Instrumentation这个词有很多意思,在维基百科中,它是 ...

  4. [LC] 76. Minimum Window Substring

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  5. python-django框架-电商项目-商品模块开发_20191124

    用户浏览记录的添加 什么时候添加历史浏览记录? 在商品详情的视图里面添加浏览记录, 之前使用的list来存储浏览记录, 注意:如果good_id之前已经浏览过了,那就要移除,conn.lrem(his ...

  6. PXE自动部署工具

    1.工具介绍1.1::本工具主要以图形界面的方式帮助使用者快速部署PXE安装Linux的基础环境环境,(如不需要可忽略相关操作)并且支持自动配置静态IP地址和为H3C设备划分VLAN. 1.2::对于 ...

  7. vyos的Xvlan配置方式

    set interfaces bridge br0 address '172.12.12.10/24' //开启一个桥借口,用于xvlan的通信 set interfaces vxlan vxlan0 ...

  8. the Uneducated are|anymore|that| so as to |die from|die of|

    定冠词加上某些形容词可以泛指一类人,谓语动词一般用复数形式,the uneducated泛指未受过教育的人, the Uneducated are more to be pitied than bla ...

  9. scrollIntoView 前的元素滚动到浏览器窗口的可视区域内 不止垂直滚动,还有水平滚动

    Element.scrollIntoView() 方法让当前的元素滚动到浏览器窗口的可视区域内 element.scrollIntoView(); // 等同于element.scrollIntoVi ...

  10. 组合数学之Pólya计数理论

    1 群 群$(G, cdot)$: 闭合, 结合律, 幺元, 逆 1.1 置换群 置换为双射$pi:[n]to [n]$, 置换之间的操作符 $cdot$ 定义为函数的复合, 即$(pi cdot s ...