mac下安装配置本地nginx
1. 前提
必须安装了homebrew,可在终端输入命令brew -v
查看是否已经安装,如果输入指令出现版本号说明已经安装成功
2. 步骤
1. 查看是否已经安装nginx
brew search nginx
2. 安装
brew install nginx
3. 启动nginx
nginx
默认端口是8080,访问http://localhost:8080/ 就能看到nginx在本计算机搭建的服务器。
4. 查看nginx安装目录
open /usr/local/etc/nginx/
5. 修改配置nginx,解决跨域
server {
# 需要被监听的端口号,前提是此端口号没有被占用,否则在重启 Nginx 时会报错
listen 8888;
# 服务名称,无所谓
server_name localhost;
# 上述端口指向的根目录
root D:/work/codet;
# 项目根目录中指向项目首页
index index.html;
client_max_body_size 20m;
client_body_buffer_size 128k;
# 由于路由的资源不一定是真实的路径,无法找到具体文件
# 所以需要将请求重写到 index.html 中,然后交给真正的 Vue 路由处理请求资源
location / {
proxy_pass https://localhost:8080/;
}
# 配置你要访问的服务器地址
location /grafana/ {
proxy_pass https://192.128.29.102/grafana/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
# for Ajax
#fastcgi_param HTTP_X_REQUESTED_WITH $http_x_requested_with;
proxy_set_header HTTP-X-REQUESTED-WITH $http_x_requested_with;
proxy_set_header HTTP_X_REQUESTED_WITH $http_x_requested_with;
proxy_set_header x-requested-with $http_x_requested_with;
}
location /audit-apiv2{
proxy_pass https://192.128.29.102/audit-apiv2/;
}
}
6. 重启nginx
nginx -s reload
7. 如果要快速停止nginx
nginx -s stop