MacOS 安装 Nginx
2020-06-29 本文已影响0人
沙漠中的猴
Nginx 介绍
Nginx 是一个自由、开源、高性能及轻量级的 HTTP 服务器和反向代理服务器,它有很多功能,主要功能为:
- 正向代理
- 反向代理
- 负载均衡
- HTTP 服务器(包含动静分离)
负载均衡
反向代理
MacOS 安装 Nginx
1. 通过 homebrew
安装 nginx
$ brew install nginx
使用 which nginx
检查是否安装成功
$ which nginx
/usr/local/bin/nginx
2. 启动 Nginx
$ nginx
2.1 访问 Nginx
在浏览器中输入 localhost:8080
即可访问 Nginx 界面
3. 配置 Nginx
配置文件的位置:
/usr/local/etc/nginx/nginx.conf
3.1 修改默认端口号
Nginx 的默认端口号为 8080
。我们将其修改为 8088
。在修改之前先停止服务。
$ nginx -s stop
在编辑器中打开配置文件,并修改端口号
server {
listen 8088;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
保存并启动 nginx
$ nginx
在浏览器中访问:localhost:8088