Nginxconfiguration托pipe一个Web应用程序和一个静态网站

现在我使用Nginx作为反向代理来服务我的Node.js应用程序。

这是/etc/nginx/sites-enabled/default文件中的configuration

 server { listen 443; server_name example.com; ssl on; # Use certificate and key provided by Let's Encrypt: ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; # Pass requests for / to localhost:8000: location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_pass http://localhost:8000/; proxy_ssl_session_reuse off; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; proxy_redirect off; } } 

我可以通过键入example.com或example.com:8000来访问这个networking应用程序。

我也在这个path/home/ftp/single上传了一个静态网站文件。 最初,我想使这个path可访问(然后我可以访问静态网站通过example.com/home/ftp/single)

我做不到,我妥协的解决scheme是在default文件中添加一个服务器块:

 server { listen 2222; root /home/ftp/single; } 

所以现在如果我inputexample.com:2222我将访问静态文件。

不过,我对此不是很满意。 我期望的情况是当我访问example.com/static/,我将访问静态文件,就像我在当前设置下键入example.com:2222

如果您的文件位于/home/ftp/single并希望通过http://example.com/home/ftp/single访问它们,则需要以下附加location块:

 location /home/ftp/single { root /; index index.html; try_files $uri $uri/ =404; } 

这个告诉nginx请求以/home/ftp/single开头的规范化URIpath,以便根文件夹是文件系统根,然后try_files告诉nginx查找URI中指定的文件(string在域名为虚拟服务器)。

index指令告诉nginx当请求指向没有文件名的path时显示哪个文件。

但是,将root指令设置为指向文件系统根目录不是一个好主意,因为它可能会将其他系统文件暴露给远程访问者。

我会推荐这种方法:

 location /single { root /home/ftp; index index.html; try_files $uri $uri/ =404; } 

然后,访问http://example.com/single将在/home/ftp/single/index.html处显示该文件。

我们需要知道域名是肯定的。 但是,我的猜测是你从http转发到https,并没有https服务器可用,因为你评论它。

如果你“curl -i http://example.com ”你的域名可能会得到回应,告诉你“301redirect到https://example.com ”。

如果您不请更新您的问题,以提供更多信息,包括

  • curl http和https网站
  • 访问这些卷发的日志(不只是随机的日志,关联他们给我们)
  • 这些卷发的错误日志(不只是随机日志,为我们关联它们)

当然,这可能是一个DNS问题,但你没有告诉我们任何关于你的DNS。