大网数据广告活动
服务器运维问答

Configure nginx to serve static files

· 52CE 我爱测

I'm trying to serve static files(HTMLs, JS and CSS) from a Google compute engine instance running Debian 8. I used git to clone the web app to the folder /var/www/prod/app with command sudo git clone <my repo> I made a conf file …

问题原文

原帖链接 · Shabin Muhammed · CC BY-SA 3.0

I'm trying to serve static files(HTMLs, JS and CSS) from a Google compute engine instance running Debian 8. I used git to clone the web app to the folder /var/www/prod/app with command

sudo git clone <my repo>

I made a conf file in sites-enabled folder app.conf. Here's the content

server {
    listen 80;
    root /var/www/prod/app;
    location / {
    }
}

Isn't this config enough to make my machine serve the files when I type my machine's ip address/path ?

I see the welcome to nginx page when I type my instance's ip address in browser. But none of the files in prod/app are served. I get 404 for all the paths I try. Could someone help me configure this.

已采纳解答

原帖链接 · Shabin Muhammed · CC BY-SA 3.0

I figured it out. Nginx has a default config file (without the extension ".conf") in the following path

/etc/nginx/sites-enable/default

The default config has a server block for default_server that serves the folder /var/www/html. This would override any config I made for serving static files without a server_name field.

I commented out these lines and things are working as expected.

Thanks to Alexy Ten and Tero Kilkaken for pointing me in the right direction.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-04-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。