小编Chr*_*ris的帖子

使用Nginx从一台服务器提供两个站点

我有一个Rails应用程序在我的服务器上运行,现在我想添加另一个.

我希望Nginx检查请求是什么,并根据域名分割流量

两个站点都有自己的nginx.conf符号链接到启用了站点,但是从nginx启动时出错 Starting nginx: nginx: [emerg] duplicate listen options for 0.0.0.0:80 in /etc/nginx/sites-enabled/bubbles:6

他们都在聆听80但不同的事情.

网站#1

upstream blog_unicorn {
  server unix:/tmp/unicorn.blog.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  server_name walrus.com www.walrus.com;
  root /home/deployer/apps/blog/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @blog_unicorn;
  location @blog_unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://blog_unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}
Run Code Online (Sandbox Code Playgroud)

网站二:

upstream bubbles_unicorn {
  server …
Run Code Online (Sandbox Code Playgroud)

proxy nginx

64
推荐指数
2
解决办法
5万
查看次数

sqlite3.OperationalError:无法打开数据库文件

在Django中设置服务器时出现此错误.它是sqlite3,这意味着它应该创建.db文件但它似乎没有这样做.我已经规定SQLite作为后端和绝对文件路径,在哪里放置它,但没有运气.

这是一个错误还是我做错了什么?(只是想,在Ubuntu中指定的绝对文件路径是不同的吗?)

这是我的settings.py文件的开头:

# Django settings for OmniCloud project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': '~/Harold-Server/OmniCloud.db',                      # Or path to database file if using sqlite3.
    'USER': '',                      # Not used with sqlite3.
    'PASSWORD': '',                  # Not used with sqlite3.
    'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': …
Run Code Online (Sandbox Code Playgroud)

python database sqlite django django-settings

41
推荐指数
5
解决办法
11万
查看次数

Postgres.app无法在端口5432上启动

我正在使用http://postgresapp.com.在菜单栏中,它给出错误"无法在端口5432上启动".同样,如果我尝试从终端启动服务器,我得到:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud)

我也运行pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start 并获得输出server starting但在连接到psql时仍然会得到相同的错误.

postgresql macos

38
推荐指数
11
解决办法
6万
查看次数

将列添加到SQLAlchemy表

我使用SQLAlchemy创建了一个表,忘了添加列.我基本上想要这样做:

users.addColumn('user_id', ForeignKey('users.user_id'))
Run Code Online (Sandbox Code Playgroud)

这是什么语法?我在文档中找不到它.

python terminal sqlalchemy

31
推荐指数
6
解决办法
5万
查看次数

处理应用程序代理和在视图之间切换

我收到一个关于传递*const _strong到类型的语义问题的警告,id无论我改变什么,似乎无法修复它.

我目前有两个观点,并编写了这段代码.在iPadSpeckViewController.m中,这是应该在视图之间切换的方法:

-(IBAction) touchProducts {
    ProductsViewController *controller = [[ProductsViewController alloc]
            initWithNibName:@"Products" bundle:nil];
    controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    controller.delegate = self;
    [self presentModalViewController:controller animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

对于ProductsViewController.h:

@interface ProductsViewController : UIViewController {
    id<ProductsViewControllerDelegate> delegate;
}
@property(nonatomic, retain)
    IBOutlet id<ProductsViewControllerDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)

ProductsViewController.m包含:

@synthesize delegate;
Run Code Online (Sandbox Code Playgroud)

但观点不转换......思考?

编辑:这是确切的警告,因为它显示在"controller.delegate = self;"行上 在iPadSpeckViewController.m中:

/Developer/iPadSpeckApp/iPadSpeckApp/iPadSpeckAppViewController.m:17:27:{17:27-17:31}: warning: passing 'iPadSpeckAppViewController *const __strong' to parameter of incompatible type 'id<ProductsViewControllerDelegate>' [3]
Run Code Online (Sandbox Code Playgroud)

iphone delegates objective-c uiviewcontroller

29
推荐指数
1
解决办法
2万
查看次数

创建正则表达式数组Javascript

我想创建一个函数,将密码与一些常见的愚蠢的密码进行比较,这样用户就无法选择其中一个,但是到目前为止我写的函数,当放在脚本标签之间时,不会导致javascript被识别(通过Firebug).我假设阵列创建有问题.

function unacceptable(pwd){
    var unforgivable = [
    /password/gi, /*g matches any occurance of sequence, i checks case insensitive*/
    /12345678/g,
    /8675309/g,
    /[a-z]{8,}/gi,
    /qwerty/gi,
    /asdfg/gi,
    /qazwsx/gi,
    /zxcvb/gi,
    /letmein/gi,
    /trustno1/gi,
    /omnicloud/gi,
    /monkey/gi];
    for (var i=0; i<unforgivable.length; i++)
        if(pwd.match(unforgivable[i])) return true;
    return false;
} 
Run Code Online (Sandbox Code Playgroud)

javascript regex arrays passwords

25
推荐指数
2
解决办法
3万
查看次数

在JS中插入兄弟节点

所以我有一个带有一些预标签的div,如下所示:

<div id="editor" >
    <pre contentEditable="true">1</pre>
    <pre contentEditable="true">2</pre>
    <pre contentEditable="true">3</pre>
</div>
Run Code Online (Sandbox Code Playgroud)

现在我想使用Javascript将新pre节点放在1和2之间.我一直在尝试这样做(因为我理解DOM是一个双重链接的树),但我感觉可能是指针因为我正在接近它,所以不可编辑.

(只是事件处理程序中的一个片段,e是事件)

var tag = e.srcElement;
    if(tag.nextSibling){
        var next = tag.nextSibling;
        var newPre = document.createElement('pre');
        newPre.setAttribute("contentEditable", "true");
        newPre.innerHTML = "boom";
        tag.nextSibling = newPre;
        newPre.nextSibling = next;
    }
Run Code Online (Sandbox Code Playgroud)

最后两行来自我的c ++经验,但在JS中感觉很吵.我该如何设置一个新的兄弟节点?

html javascript dom siblings

24
推荐指数
2
解决办法
3万
查看次数

OperationalError:(OperationalError)无法打开数据库文件无无

尝试使用SQLAlchemy格式化数据库,但是当我在元数据上运行create_all时,出现上述错误.我使用以下路径为用户Tyre77创建了引擎:

engine = create_engine('sqlite:////tyre77/OmniCloud/database.db')
Run Code Online (Sandbox Code Playgroud)

我走过去,在那条路上有一个'database.db'文件,但也许我打错了?

python sqlite terminal sqlalchemy

21
推荐指数
2
解决办法
2万
查看次数

Clojure:只能从尾部位置重复出现

我试图以递归方式反转列表,但我正在 Can only recur from tail position运行.这是什么意思,我的代码如何改进,以便它的工作?

(defn recursive-reverse [coll]
  (loop [coll coll]
    (if (< (count coll) 2) '(coll)
      (conj (first coll) (recur (rest coll)))
      )))
Run Code Online (Sandbox Code Playgroud)

编辑

奥斯卡解决方案的输出.它适用于列表但不适用于矢量?

user=> (= (recursive-reverse [1 2 3 4 5]) (recursive-reverse '(1 2 3 4 5)))
false
user=> (= '(1 2 3 4 5) [1 2 3 4 5])
true
user=> (recursive-reverse [1 2 3 4 5])
[1 2 3 4 5]
user=> (recursive-reverse '(1 2 3 4 5))
(5 4 3 2 …
Run Code Online (Sandbox Code Playgroud)

recursion clojure

19
推荐指数
2
解决办法
7651
查看次数

设置默认数据库连接Rails

我的rails应用程序有自己的MySql数据库(并且需要mysql2 gem),但也需要连接一个特定模型的外部MongoDB数据库(因此我在Gemfile中包含了mongoid和bson_ext).现在,当我尝试为新模型生成迁移时,它会告诉我

$ rails g migration CreateLocations
       error  mongoid [not found]
Run Code Online (Sandbox Code Playgroud)

当我生成Location模型时,它包含Mongoid :: Document,因此Rails显然认为它使用外部数据库作为我的主数据存储区.

databse.yml:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: associalize_development
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock
Run Code Online (Sandbox Code Playgroud)

mongoid.yml:

development:
  host: pearl.mongohq.com
  port: 27019
  username: asfasdf
  password: sadfasdf
  database: app4574678

test:
  host: pearl.mongohq.com
  port: 27019
  username: asdfadhasdfa
  password: hadsadfas
  database: app4574678

production:
  host: pearl.mongohq.com
  port: 27019
  username: asdfdfsasda
  password: afdasdfdasdf
  database: app4574678
Run Code Online (Sandbox Code Playgroud)

UPDATE 使用Mongo的模型

class ExternalMongoModel
  include Mongoid::Document

  field :title
  field :long_title
  field :deal_type
  field :merchandise_type
  field …
Run Code Online (Sandbox Code Playgroud)

database activerecord ruby-on-rails mongoid

18
推荐指数
3
解决办法
5189
查看次数