在数字海洋VPS上使用Nginx设置Uberjar

时间:2015-08-18 03:36:14

标签: nginx clojure proxy vps uberjar

我使用了以下链接中的说明:

"Hosting Clojure Web Apps in 7 Easy Steps"

我知道uberjar有效,因为我在我的开发机器和VPS上测试了它。

只是Nginx似乎无法找到它。 我怀疑它与此站点代码有关:

# Web sockets
location /chsk {
proxy_pass http://backend/chsk;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

...但我不知道如何纠正它...感谢您的帮助!

另一件事:在站点文件的“上游后端”中,我尝试了127.0.0.1:3000和0.0.0.0:3000但没有成功。

这是默认的网站配置:

server {
# Replace this port with the right one for your requirements
listen [::]:80 ipv6only=off;

# Multiple hostnames separated by spaces.  Replace these as well.
server_name clmitchell.net www.clmitchell.net main.clmitchell.net
books.clmitchell.net dna.clmitchell.net help.clmitchell.net
history.clmitchell.net svcs.clmitchell.net;
server_name_in_redirect off;

root /data/nginx/www/$host;

error_page 401 /error/401.shtml;
error_page 402 /error/402.shtml;
error_page 403 /error/403.shtml;
error_page 404 /error/404.shtml;
error_page 500 501 502 503 504 /error/500.shtml;

location ^~ /error/ {
  internal;
  root /data/nginx/www/www.clmitchell.net;
}


access_log /var/log/nginx/$host-access.log;
error_log /var/log/nginx/error.log;

index index.php index.html index.htm default.html default.htm;
# Support Clean (aka Search Engine Friendly) URLs
location / {
      try_files $uri $uri/ /index.php?$args;
}

# serve static files directly
location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
  access_log off;
  expires max;
}

location ~ \.php$ {
  try_files $uri =404;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  include fastcgi_params;
}

location ~ \.scm$ {
  include fastcgi_params;
  fastcgi_intercept_errors on;
  # By all means use a different server for the fcgi processes if you need to
  fastcgi_pass  127.0.0.1:9981;
}

  location ~ /\.ht {
    deny  all;
  }
}

我从服务器名称列表中删除了history.clmitchell.net。

这是当前的历史网站配置:

upstream backend {
   server 104.131.29.212:3000 fail_timeout=0;
}

server{
  listen [::]:80 ipv6only=off;
  server_name localhost history.clmitchell.net;

  access_log /var/log/hist_access.log;
  error_log /var/log/hist_error.log;

  root /var//resources/public;

  # Web sockets
  location /chsk {
    proxy_pass http://backend/chsk;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }

  # Static assets
  location / {
    try_files $uri @backend;
  }

  # The backend server
  location @backend {
    proxy_pass http://backend;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_redirect off;
  }
}

在历史网站配置上有一个重复的“listen”指令,我删除了...但由于某种原因,我仍然收到错误:'

  

sudo nginx -t   nginx:[emerg]在/ etc / nginx / sites-enabled / hist中为[::]:80重复监听选项:6   nginx:配置文件/etc/nginx/nginx.conf测试失败

2 个答案:

答案 0 :(得分:1)

请尝试

proxy_pass http://backend;

如果您的上游定义如下,请确保您可以访问http://127.0.0.1:3000/chsk

upstream backend {
    server 127.0.0.1:3000;
}

或者如果我们只有一个后端服务器,我们可以使用proxy_pass而不定义上游后端。 e.g。

proxy_pass http://127.0.0.1:3000;

答案 1 :(得分:0)

我今天学到了一个新课:Nginx网络服务器上没有两个网站可以拥有相同的监听端口! 我将新网站移动到新端口并更新了所有链接......问题解决了!