【问题标题】:Setup pretty local development URLs with nginx on Mac OS X在 Mac OS X 上使用 nginx 设置漂亮的本地开发 URL
【发布时间】:2015-01-05 02:27:20
【问题描述】:

我有一个可以从 127.0.0.1:8000 访问的 Django 服务器设置

我刚刚在 Mac OS X Yosemite 上安装了 nginx,可以通过localhost:80访问“欢迎使用 nginx”屏幕

我希望能够在 local.ingledow.co.uk 上设置本地开发环境,但是当我访问该 URL 时,它会将我重定向到我的实时站点:david.ingledow.co.uk

我确实有一个带有 DNSimple 的通配符 URL 转发器,它会像这样重定向:

*.ingledow.co.uk > david.ingledow.co.uk

但我已经删除了。

我已添加此 CNAME:local.ingledow.co.uk > 127.0.0.1

这不应该影响我设置本地 nginx 服务器的方式。

那么,如何在 Mac 上创建一个 nginx 服务器,将我的 127.0.0.1:8000 Django 项目显示到自定义域 (local.ingledow.co.uk)。

这是我的 nginx 设置:

/usr/local/etc/nginx/nginx.conf 中的默认 Nginx 配置

#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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

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

    # INCLUDES

    include /Users/dingledow/etc/nginx/*.conf;

}

ingledow.conf 位于 /Users/dingledow/etc/nginx/ingledow.conf

server {
  listen       80;
  server_name  local.ingledow.co.uk;

  location / {
      root /Users/dingledow/Documents/Work/Ingledow/git/my_site2/;
      index index.html index.htm index.php;
      autoindex on;
  }
}

我不确定 Apache 是否与 nginx 冲突?还是我刚刚设置的nginx不正确?

【问题讨论】:

    标签: django macos apache nginx dns


    【解决方案1】:

    向您的注册商设置 CNAME 根本没有帮助,您应该删除它。

    完成这项工作的唯一方法是在 /etc/hosts 编辑本地 HOSTS 文件并添加指向 localhost 的指针:

    127.0.0.1. local.ingledow.co.uk   
    

    然后您需要在端口 80 而不是 8000 上运行开发服务器,或者配置 nginx 以通过 gunicorn 或 uwsgi 运行您的站点 - 文档告诉您如何做到这一点。

    【讨论】:

    • 我现在收到 403 禁止错误?我更新了我的主机和 nginx。 Nginx 在 80 上监听,但我无法让 Django 在 80 上运行?
    • 你不能在同一个端口上同时运行 nginx 和 Django 开发服务器。如果你想在那里使用开发服务器,那么你必须禁用 nginx;否则,正如我所说,通过代理到 gunicorn 之类的东西来配置 nginx 以运行 Django。
    猜你喜欢
    • 2017-12-27
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多