美文网首页
celery使用nginx 向外提供静态页面(on macos)

celery使用nginx 向外提供静态页面(on macos)

作者: 花括弧 | 来源:发表于2019-07-30 18:56 被阅读0次

使用celery产生的首页静态页面index.html,要想被外界访问到。
就要由celery所在主机的nginx 向外界提供(访问index.html)的服务。
我的celery在mac上,因此需要在mac上安装nginx

安装nginx

1. 更新homebrew

$ brew update

2. 安装nginx

$ brew install nginx
nginx 目录结构

由上图可知:

  • 根文件路径:/usr/local/var/www
  • nginx的配置文件路径:/usr/local/etc/nginx/nginx.conf
  • nginx会加载 该/usr/local/etc/nginx/servers/目录下的 所有文件
  • 开机启动nginx:$ brew services start nginx(不需要开机启动,直接使用$ nginx命令)
# 停止nginx
$ sudo /usr/local/nginx/sbin/nginx -s stop

# 重启nginx
$ nginx -s reload

# 启动时,带上配置文件
$ sudo nginx -c /usr/local/etc/nginx/nginx.conf

在nginx的配置文件(/usr/local/etc/nginx/nginx.conf)中,添加如下的一个server:

server {
        listen       8989;
        server_name  localhost;
        
        location /static {
            alias /Users/leesam/dailyfresh/static/;  
        }
        location / {
            root   /Users/leesam/dailyfresh/static/;
            index  index.html index.htm;
        }
}

之后在浏览器中输入10.211.55.2:8989(10.211.55.2是macbook的ip, 8989端口号), 如果可以看到index.html页面。就说明 配置好了(由nginx向外提供 静态页面index.html的访问)。

相关文章

网友评论

      本文标题:celery使用nginx 向外提供静态页面(on macos)

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