Mac环境下安装nginx并当地部署项目
1、条件必须安装了homebrew,可在终端输入命令brew -v检察是否已经安装,假如输入指令出现版本号阐明已经安装乐成
https://img-blog.csdnimg.cn/5bfec2462eaf490984ff6ac9de428d38.png
假如未安装先安装 homebrew官网地点
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
安装完之后再次输入brew -v检察是否有版本号
2、实行brew search nginx 命令查询要安装的软件是否存在
https://img-blog.csdnimg.cn/dfd0f4f22eab4c08af7eec2d4f7313a4.png
3、实行brew install nginx安装nginx
https://img-blog.csdnimg.cn/38db727c519748b1976cfcdaa757716f.png
4、实行brew info nginx信息,可以检察ngxin下载的位置以及nginx配置文件存放路径等信息(以下是安装乐成所展示的信息,不乐成会提示其他信息)路径不用死记硬背,忘记了实行命令检察就可以了
https://img-blog.csdnimg.cn/78410fea8e1f4d728c8486655baeebc0.png
https://img-blog.csdnimg.cn/ed46e5d19b124f958c9ef5d0a2f85d35.png
5、检察nginx存放目次是不是如第4步所说的一致
终端实行以下命令:
https://img-blog.csdnimg.cn/3e5a608af94f43b483eb7973aa9acb5d.png
终端实行以下命令:
https://img-blog.csdnimg.cn/5acef85463c0415baeed510ac121d6e3.png
六、在终端cd /opt/homebrew/Cellar/nginx/1.23.2/bin进入bin目次,然后实行nginx命令(没有报错就是启动乐成)下图表现的端口号等下会说
https://img-blog.csdnimg.cn/e815b96e930948bd8be9e84a2f6838df.png
7、根据需求或者实际环境,修改nginx的配置文件:
上图看到的端口号需要在 open /opt/homebrew/Cellar/nginx/1.23.2/bin此目次下的nginx.conf里面修改,
修改之后重新运行nginx -s reload命令就能打开你自定义的端口号啦
https://img-blog.csdnimg.cn/7fe4c301e3a643759234b6836596bbc5.png
编辑器打开:
https://img-blog.csdnimg.cn/38249cfb10a94956b16541ba82f83d87.png
八、部署项目
1.首先需要将打包好的项目放到你指定的的路径下
我是存放在open /opt/homebrew/Cellar/nginx/1.23.2/duxi 此目次下
https://img-blog.csdnimg.cn/68d3d44a0f4a4da4aa761d1e60a99812.png
在nginx.conf里面的server对象下配置
当地测试没有配置代理如下配置
https://img-blog.csdnimg.cn/d6ed9e921e484e97bd9956cdcc727693.png
当地测试配置了代理
https://img-blog.csdnimg.cn/e748a20688434be8b938e4ff5157bca5.png
nginx.conf配置文件如下:
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pid logs/nginx.pid;
events {
worker_connections1024;
}
http {
include mime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfile on;
#tcp_nopush on;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
server {
listen 8086;
server_namelocalhost;
#charset koi8-r;
#access_loglogs/host.access.logmain;
# location / {
# root html;
# indexindex.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_page404 /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_indexindex.php;
# fastcgi_paramSCRIPT_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 {
# denyall;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_namesomenamealiasanother.alias;
# location / {
# root html;
# indexindex.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_namelocalhost;
# ssl_certificate cert.pem;
# ssl_certificate_keycert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout5m;
# ssl_ciphersHIGH:!aNULL:!MD5;
# ssl_prefer_server_cipherson;
# location / {
# root html;
# indexindex.html index.htm;
# }
#}
include servers/*;
}
配置完毕之后,重启nginx(nginx -s reload),然后把当地项目运行起来(npm run serve),然后把端口号改成nginx里面配置的端口号即可看到当地部署的项目
https://img-blog.csdnimg.cn/2dc87670028c498eb8ba937787829531.png
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]