随笔 - 22,  文章 - 0,  评论 - 3,  阅读 - 2162

下载nginx并配置

首先下载nginx

brew install nginx

查看nginx

brew info nginx

截屏2023-11-21 14.55.39.png

启动nginx

niginx
brew services start nginx // 重启的命令是: brew services restart nginx

因为nginx默认的端口号是8080,因此我们页面访问 http://localhost:8080 即可,看到如下信息:

截屏2023-11-21 15.50.57.png

使用nginx配置启动vue项目

打开nginx

open  /opt/homebrew/Cellar/nginx

截屏2023-11-21 15.57.40.png

将打包的文件放到html里面

截屏2023-11-21 16.06.47.png

使用vscode 打开nginx

code /opt/homebrew/etc/nginx/nginx.conf

将下面配置替换

    location / {
        #    root   html; 这个是一开始默认的html
            root  /opt/homebrew/Cellar/nginx/1.25.3/html/dist;   将
            index  index.html index.htm;
        }

        location /api/ {
            rewrite ^/api(/.*)$ $1 break;
            proxy_pass http://10.83.40.232:19000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

在运行nginx 就可以使用了

nginx  //地址是localhost:8080

使用本地ip地址

ifconfig | grep "inet"  //查看ip地址

4093812-fb2ac5994189fc1b.jpg

nginx在mac常用命令

在 macOS 中,Nginx 的命令与其他 Unix/Linux 系统类似。以下是一些常用的 Nginx 命令:

  1. 启动 Nginx:

    sudo nginx
    
  2. 停止 Nginx:

    sudo nginx -s stop
    
  3. 重启 Nginx:

    sudo nginx -s reload
    
  4. 查看 Nginx 版本:

    nginx -v
    
  5. 测试 Nginx 配置文件语法是否正确:

    sudo nginx -t
    

    如果配置文件语法正确,会输出 nginx: configuration file /path/to/nginx.conf test is successful

  6. 关闭 Nginx:

    sudo nginx -s quit
    

这些命令假定你的 Nginx 配置文件的路径是默认的 /etc/nginx/nginx.conf。如果你的 Nginx 安装路径或配置文件路径不同,需要相应地调整命令。

请注意,在 macOS 中使用 sudo 可能需要输入管理员密码。确保你有足够的权限来执行这些命令。

posted on   awite  阅读(148)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示