【问题标题】:Problems to use nginx in windows server 2008 R2 (nodejs + express + mongodb)windows server 2008 R2中使用nginx的问题(nodejs + express + mongodb)
【发布时间】:2015-05-23 13:20:09
【问题描述】:

我正在尝试在 Windows Server 2008 R2 中使用 nginx,但是:

它在 Windows Server 2008 R2 上运行:

但是,当我尝试从我的计算机访问该页面时:

我确定地址 IP 是正确的,因为服务器正在运行 IIS,我可以访问同一 IP(不同端口)中的其他页面。

nginx.conf

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

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

【问题讨论】:

  • 你在 Windows 防火墙中打开了 3000 端口吗?
  • 是的,但它不起作用。
  • 你的 nginx.conf 是什么样的?
  • 我在上面贴了 :) 谢谢

标签: windows node.js nginx server windows-server-2008-r2


【解决方案1】:

问题是 server_name 设置为“localhost”,因此只有发送到该地址的请求才会起作用。

将其设置为服务器的 IP 地址(如果它是静态的并且您只能通过 IP 访问它),或者将其设置为“_”以便它可以捕获所有请求

server_name _;

【讨论】:

  • 我使用命令关闭服务器:taskkill /f /IM nginx.exe 并更改为 server_name 108.171.168.169;在 server_name _ 之后;但它不起作用:(
【解决方案2】:

我发现问题不在于 nginx 的配置,而只是我服务器仪表板的权限。

【讨论】:

    猜你喜欢
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-02
    • 2020-03-14
    相关资源
    最近更新 更多