nginx 不提供文件服务

nginx 不提供文件服务

我已将一个目录复制到/var/www命名中mysite;然后我创建了一个文件,sites-available以便将配置设置为指向该目录 ( ) 及其在( )/etc/nginx/sites-available/mysite中的符号链接:sites-enabled/etc/nginx/sites-enabled/mysite

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

    root /var/www/otsui;

    index index.html;

    server_name _;

    location / {
        try_files $uri $uri/ =404;
    }

}

但是当我尝试获取时http://localhost:4000/,我得到的This site can’t be reached页面意味着没有提供任何服务。

我也尝试过重新启动nginx服务。

我有一个 Debian 杰西。

这些是我的防火墙:

root@mylab:/var/www# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
DOCKER-USER  all  --  anywhere             anywhere            
DOCKER-ISOLATION  all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (2 references)
target     prot opt source               destination         

Chain DOCKER-ISOLATION (1 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-USER (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

我还尝试将我的网站文件复制到默认目录中,即/var/www/html;但即使我重新启动了服务,在浏览器中导航http://127.0.0.1:3000/仍然显示欢迎页面。nginxnginx

答案1

我解决了这个问题;问题是我没有包含/etc/nginx/sites-enabled/在内/etc/nginx/nginx.conf以便从中加载配置。服务restart上线后nginx,我的 Web 应用程序已完全部署。

我应该提到的是,我还检查了命令的输出nginx -t,以确保nginx配置中的每个更改都正确;成功重新配置的输出是:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

顺便说一句,这是我现在的 nginx 配置:

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;
    include /etc/nginx/sites-enabled/*;
}

相关内容