mac上nginx使用

mac 使用brew安装nginx 各种命令

安装:brew install nginx      或者      sudo brew install nginx

启动:brew services start nginx       或者         sudo brew services start nginx

重启:brew services restart nginx        或者         sudo brew services restart nginx

停止:brew services stop nginx           或者            sudo brew services stop nginx

查看:cat usr/local/etc/nginx/nginx.conf

编辑:vi usr/local/etc/nginx/nginx.conf

安装 homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

使用homebrew安装

sudo brew install nginx

启动 Nginx

sudo nginx

停止 Nginx 方法1

sudo nginx -s . top

停止 Nginx 方法2:在终端输入
ps -ef | grep nginx 查找 nginx: master process 存在的话直接 pkill -9 nginx

修改配置文件重新加载

sudo nginx -s reload

常用的指令有:

nginx -s reload 重新加载配置

nginx -s reopen 重启

nginx -s stop 停止 nginx -s quit 退出

nginx -V 查看版本,以及配置文件地址

nginx -v 查看版本

nginx -c filename 指定配置文件

nginx -h 帮助

nginx -t 查看配置是否正确

排错思路

一般都是端口问题或配置问题

  • 先说端口问题
    查找配置文件位置在终端输入 sudo nginx -t

输入cat /usr/local/etc/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       8080;
      server_name  localhost;

      #charset koi8-r;

      #access_log  logs/host.access.log  main;

            # 允许请求地址跨域 * 做为通配符
            add_header 'Access-Control-Allow-Origin' '*' always;
            # 设置请求方法跨域
            add_header 'Access-Control-Max-Age' '1000' always;
            # 设置是否允许 cookie 传输
            add_header 'Access-Control-Allow-Methods' "POST, GET, OPTIONS, DELETE, PUT" always;
             # 设置请求头 这里为什么不设置通配符 * 因为不支持
            add_header 'Access-Control-Allow-Headers' "x-requested-with, Content-Type, origin, authorization, accept, client-security-token" always;

            # 设置 options 请求处理
            if ( $request_method = 'OPTIONS' ) {
                return 200;
            }

      location /webShell {
           # 设置反向代理
          proxy_pass http://127.0.0.1:8081;
          proxy_set_header Host $host:$server_port;
          proxy_set_header X-Forwarded-Host $server_name;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }

     location / {
               # 设置反向代理
              proxy_pass http://127.0.0.1:1841;
              proxy_set_header Host $host:$server_port;
              proxy_set_header X-Forwarded-Host $server_name;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          }

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

    }
    include servers/*;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值