温馨提示×

nginx.conf中的server块如何配置

小樊
188
2024-08-14 01:20:36
栏目: 编程语言
亿速云云数据库,读写分离,安全稳定,弹性扩容,低至0.3元/天!! 点击查看>>

在nginx.conf中的server块配置如下:

server {
    listen 80;
    server_name example.com;

    location / {
        root /var/www/html;
        index index.html;
    }

    location /api {
        proxy_pass http://localhost:3000;
    }
}

这个例子中,server块设置监听端口为80,server_name为example.com。在location /指令中配置了根目录和默认首页文件,同时在location /api中配置了反向代理到本地的3000端口。根据实际需求,可以根据需求配置更多的location和指令。

亿速云「云数据库 MySQL」免部署即开即用,比自行安装部署数据库高出1倍以上的性能,双节点冗余防止单节点故障,数据自动定期备份随时恢复。点击查看>>

推荐阅读:nginx.conf中http块的作用是什么

0