Nginx的安装
1.打开终端
2.安装Command Line tools
xcode-select --install
3.安装brew命令
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
4.安装nginx
brew install nginx
5.启动nginx
sudo nginx
nginx就安装好了,可以在浏览器访问了,默认端口为8080,
在浏览器输入 http://localhost:8080/ 就能看到nginx在本计算机搭建的服务器
Nginx的配置
在nginx下配置对应的staic文件夹
server {
listen 80;
server_name mapi.cxtchain.org;
access_log /var/log/nginx/mapi-access.log;
location / {
proxy_pass http://127.0.0.1:9090;
}
location /app/ {
root /;
}
}
这里第二个location就是配置的static文件的路径,如果用root,那么路径就会追加到路径后面,比如:
location /app/ {
root /123/ironman/;
}
访问sample.com/app/xxx => /123/ironman/app/xxx
root可以替换为alias这样就直接就是alias后面的路径
location /app/ {
alias /123/ironman/;
}
`sample.com/app/xxx` => `/123/ironman/xxx`
常用命令
nginx -s stop //停止
nginx -s reload //重新加载配置文件
nginx //启动nginx
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx
sudo systemctl reload nginx