Mac环境下安装nginx并本地部署项目

这篇具有很好参考价值的文章主要介绍了Mac环境下安装nginx并本地部署项目。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1、前提

必须安装了homebrew,可在终端输入命令brew -v查看是否已经安装,如果输入指令出现版本号说明已经安装成功
Mac环境下安装nginx并本地部署项目,vue,macos,nginx

如果未安装先安装(homebrew官网地址)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

安装完之后再次输入brew -v查看是否有版本号

2、执行brew search nginx 命令查询要安装的软件是否存在

Mac环境下安装nginx并本地部署项目,vue,macos,nginx

3、执行brew install nginx安装nginx

Mac环境下安装nginx并本地部署项目,vue,macos,nginx

4、执行brew info nginx信息,可以查看ngxin下载的位置以及nginx配置文件存放路径等信息(以下是安装成功所展示的信息,不成功会提示其他信息)路径不用死记硬背,忘记了执行命令查看就可以了

Mac环境下安装nginx并本地部署项目,vue,macos,nginx

Mac环境下安装nginx并本地部署项目,vue,macos,nginx

5、查看nginx存放目录是不是如第4步所说的一致

终端执行以下命令:
Mac环境下安装nginx并本地部署项目,vue,macos,nginx
终端执行以下命令:
Mac环境下安装nginx并本地部署项目,vue,macos,nginx

六、在终端cd /opt/homebrew/Cellar/nginx/1.23.2/bin进入bin目录,然后执行nginx命令(没有报错就是启动成功)下图显示的端口号等下会说

Mac环境下安装nginx并本地部署项目,vue,macos,nginx

7、根据需求或者实际情况,修改nginx的配置文件:

上图看到的端口号需要在 open /opt/homebrew/Cellar/nginx/1.23.2/bin此目录下的nginx.conf里面修改,
修改之后重新运行nginx -s reload命令就能打开你自定义的端口号啦
Mac环境下安装nginx并本地部署项目,vue,macos,nginx
编辑器打开:
Mac环境下安装nginx并本地部署项目,vue,macos,nginx

八、部署项目

1.首先需要将打包好的项目放到你指定的的路径下
我是存放在open /opt/homebrew/Cellar/nginx/1.23.2/duxi 此目录下
Mac环境下安装nginx并本地部署项目,vue,macos,nginx
在nginx.conf里面的server对象下配置

本地测试没有配置代理如下配置
Mac环境下安装nginx并本地部署项目,vue,macos,nginx
本地测试配置了代理
Mac环境下安装nginx并本地部署项目,vue,macos,nginx
nginx.conf配置文件如下:


#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       8086;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        # location / {
        #     root   html;
        #     index  index.html index.htm;
        # }



        location /MARKETING/ {
            root /opt/homebrew/Cellar/nginx/1.23.2/duxi;
            try_files $uri $uri/ /MARKETING/index.html;
        }
        location /MARKETING/API/  {
            proxy_pass http://localhost:8082/marketing/;
        }

       

        # 测试
        location /MY_PROJECT/ {
            root /opt/homebrew/Cellar/nginx/1.23.2/duxi;
            try_files $uri $uri/ /MY_PROJECT/index.html;
        }
        # location /MARKETING/API/  {
        #     proxy_pass http://localhost:8082/marketing/;
        # }

        #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;
        #}
    }


    # 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;
    #    }
    #}
    include servers/*;
}

配置完毕之后,重启nginx(nginx -s reload),然后把本地项目运行起来(npm run serve),然后把端口号改成nginx里面配置的端口号即可看到本地部署的项目
Mac环境下安装nginx并本地部署项目,vue,macos,nginx文章来源地址https://www.toymoban.com/news/detail-560155.html

到了这里,关于Mac环境下安装nginx并本地部署项目的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包