美文网首页
Mac下的Nginx的安装和使用

Mac下的Nginx的安装和使用

作者: Wardw | 来源:发表于2019-07-23 09:39 被阅读0次

    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
    

    相关文章

      网友评论

          本文标题:Mac下的Nginx的安装和使用

          本文链接:https://www.haomeiwen.com/subject/bxkslctx.html