首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx运行在. .com/port上,而不是在. .com/

问Nginx运行在. .com/port上,而不是在. .com/
EN

Server Fault用户
提问于 2018-07-26 12:59:07
回答 2查看 62关注 0票数 -1

我可能需要点帮助。我觉得我快到了,但在我的设置中错过了一些东西。

我可以连接到我的.com/3000来看到我的本地节点应用程序在服务器上运行。为了直接连接到.com,我只需要使用proxy_pass,所以我做到了

proxy_pass http://127.0.0.1:3000;

但它跑不了。

我有一个nodejs应用程序运行在本地主机上:3000在服务器上。

下面是/etc/nginx/sites-available中的默认文件

代码语言:javascript
复制
server {
    listen 80 default_server;
    listen [::]:80 default_server;


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

    server_name _;

    location / {
            proxy_pass http://127.0.0.1:3000;
    }

 }

下面是我的nginx.config文件

代码语言:javascript
复制
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
include /etc/nginx/sites-enabled/*;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
index   index.html index.htm;

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  localhost;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

     # redirect server error pages to the static page /40x.html
    #
    error_page 404 /404.html;
        location = /40x.html {
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

Update -

我在亚马逊的Ec2实例中。.com的页面显示为

我尝试过的 <#>For根指令

  1. root /var/www/app/index.html,在本例中,它只会抛给我404未找到的nginx页面**
  2. root /var/www/app,在这种情况下,它给出了403个禁止的错误**
EN

回答 2

Server Fault用户

发布于 2018-07-26 13:57:36

从您的default_server中删除nginx.config:

代码语言:javascript
复制
    listen       80; # default_server;
    listen       [::]:80; # default_server;

然后,您的default配置文件应该得到请求。另外,我只会对一个文档根使用server_name _;,当对服务器上未配置的域的请求到达时,该根应该作为最后手段使用。使用实际域名而不是_。

票数 1
EN

Server Fault用户

发布于 2018-07-30 19:45:08

这是一个相当混乱的配置文件布局。我看到了几件你应该尝试的事情:

从nginx配置中删除server块。

确保您的default配置文件保存在/etc/nginx/conf.d中,文件名以.conf结尾。这样,它将包含在nginx配置中。

当前的nginx配置不包括sites-available或sites-enabled目录中的任何文件,因此这些文件没有任何效果。

最后一个技巧,您应该使用nginx -T (注意大写T)来检查nginx在处理所有包含时实际使用的配置是什么。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/923648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档