nginx没有启动服务器

时间:2016-09-23 19:09:11

标签: node.js nginx

我刚刚在Scaleway的服务器上安装了nginx。

在我找到的这些瑕疵之后,我做到了这一点:

  • 创建了一个在端口3000上运行的节点应用程序

  • 并修改了启用站点的默认文件以对其进行测试。

以下是我的文件:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        #server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

}


server {
        listen 80;
        listen [::]:80;

        server_name mydomainename;
        location / {
                proxy_pass http://SERVER_PRIVATE_IP:3000;
        }
}

当我尝试访问指向我服务器的任何域名时,他们只是点击了默认的nginx欢迎索引文件。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

请执行以下操作:

1)编辑/etc/nginx/sites-available/default并输入:

server {
  server_name _ 127.0.0.1;
  root /var/www/html;
  index index.html;
}

2)文件/etc/nginx/sites-available/sitename包含内容:

server {

    server_name sitename.com www.sitename.com;
    root /home/sitename/public; # feel free to modify

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|mp3|xml)$ {
      expires 30d;
      add_header Pragma public;
      add_header Cache-Control "public";
    }

    location / {
      log_not_found off;
      access_log off;
      proxy_pass http://127.0.0.1:3000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }
}
符号链接:

ln -s /etc/nginx/site-available/sitename /etc/nginx/site-enabled/sitename

4)重启nginx

sudo service nginx restart 

玩得开心(: