Hello Nginx in macOS X

博客介绍了在macOS X上安装Nginx,提及默认配置文件和日志路径,还包括启动、停止、重载服务等操作。同时记录了上传文件HTTP 413错误,通过修改配置文件设定上传大小为8M来解决,也提到参考老外方案解决其他报错。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

See Official Guide
https://nginx.org/en/docs/beginners_guide.html

Install Nginx on macOS X

brew install nginx

Default config file & logs

By default, the config file path is /usr/local/etc/nginx/nginx.conf.

sudo vi /usr/local/etc/nginx/nginx.conf

and the error logs path is /usr/local/var/log/nginx/error.log.

tail -f /usr/local/var/log/nginx/error.log

Show Help

nginx -h
# or
nginx -?

Start, Stop, Reload

nginx -h
# start Nginx
nginx
# stop Nginx
nginx -s stop
# start Nginx with a.conf in current directory
nginx -p . -c a.conf
nginx -s reload

Sample configuration

#user	root;
events {

}

http {
  include /usr/local/etc/nginx/mime.types;
  server {
    listen 80;
    server_name localhost;
    client_max_body_size 10m;
    location / {
      alias /Users/wanghao/Workspace/ls-smartools-frontend/dist/;
      index index.html;
    }
  }
}

#user	root;
events {

}

http {
  server {
    listen 8080;
    server_name localhost;
    location ~ ^/qpe/(\S+)$ {
      alias /Users/wanghao/Workspace/qpe/htdocs/$1.json;
    }
  }
}

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    server {
        listen       80;
        server_name  localhost;
        location / {
                proxy_pass http://localhost:8081;
        }
        location /api/backend {
                rewrite ^/api/backend/(.*)$ /$1 break;
                proxy_pass http://127.0.0.1:3100;
        }
        location /api/pe {
                rewrite ^/api/pe/(.*)$ /qpe/$1 break;
                proxy_pass http://192.168.100.6:8080;
        }
     }
}

Reload

nginx -s reload

停止服务

nginx -s stop

指定配置文件启动

nginx -c /usr/local/etc/nginx/xxx.conf

2021-07-20 上传文件HTTP 413错误

修改配置文件

        location /api/backend {
                rewrite ^/api/backend/(.*)$ /$1 break;
                proxy_pass http://127.0.0.1:3100;
                client_max_body_size 8m;
        }

其中client_max_body_size设定文件上传大小为8M。

2021-09-17

app.jsmismatch错误

tail -f /usr/local/var/log/nginx/error.log

参考老外的解决方案

sudo nginx -s stop    
sudo rm -rf /usr/local/var/run/nginx/*    
sudo nginx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值