无法从外部访问nginx服务器

时间:2015-08-06 15:12:01

标签: nginx centos data-science-studio

我最近不得不在centOS 7服务器上设置nginx服务器。 为了运行dataiku软件。

每件事似乎都运行正常但是一旦我尝试访问这些页面,我就什么都没有。

使用本地的elinks我设法获得nginx默认网页,但不能从我的浏览器获取,所以我认为它来自我的nginx配置。

这是我的nginx.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
worker_connections  1024;
}



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

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

#gzip  on;

include /etc/nginx/conf.d/*.conf;
}

这是default.conf包含的文件:

server {
    listen       80 default;
    server_name _;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

location / {
    root   /usr/share/nginx/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   /usr/share/nginx/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;
#}
}

我真的需要这台服务器正常运行并且可以访问吗?你知道吗?

感谢您的阅读。

3 个答案:

答案 0 :(得分:8)

你应该在公共区域添加新规则,因为CentOS 7有一个firewalld。 尝试:

firewall-cmd --zone=public --add-service=http

然后去吧!

答案 1 :(得分:2)

您错过了proxy_pass配置,实际上是在您的情况下通过HTTP端口80将所有请求从后端转换为外部:

server {
    # Host/port on which to expose Data Science Studio to users
    listen 80;
    server_name _;
    location / {
        # Base url of the Data Science Studio installation
        proxy_pass http://DSS_HOST:DSS_PORT/;
        proxy_redirect off;
        # Allow long queries
        proxy_read_timeout 3600;
        proxy_send_timeout 600;
        # Allow large uploads
        client_max_body_size 0;
        # Allow protocol upgrade to websocket
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

官方文档很清楚:http://doc.dataiku.com/dss/latest/installation/reverse_proxies.html

确保您已经更新了Nginx以便能够提供WebSocket请求。

答案 2 :(得分:0)

将规则添加到永久集中并重新加载FirewallD:

sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --reload

应该可以!