肉饼博客

Talk is cheap. Show me the code.

0%

CentOS下Nginx简易部署网站

1.安装

1
yum install -y nginx // 可以root安装,CentOS

2.修改配置文件

1
2
3
4
5
6
7
8
9
// 配置文件:/etc/nginx/conf.d/default.conf

server {
listen 4000; // 修改默认监听端口
}

location ~ /api/ {
proxy_pass http://ip:port // 修改proxy配置,指向后端
}

3.修改运行时的用户(解决403 forbidden)

1
2
3
// 配置文件:/etc/nginx/nginx.conf

user root;

4.添加网站静态资源文件

1
cp -r * /user/share/nginx/html

5.启动nginx

1
systemctl start nginx

6.添加nginx开机启动

1
systemctl enable nginx