安装好nginx后,使用1
vim /etc/nginx/nginx.conf
修改配置文件。
在http{···}内增加:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 server {
listen 80;
server_name baidu.com test.baidu.com;
rewrite ^/$ /index permanent;
location /{
index form;
proxy_pass http://127.0.0.1:19192;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_read_timeout 300s;
}
location /static {
root /home/agent/agent/work/html;
}
}
这里的listen表示对外的端口,监听的是80端口,server_name是配置的域名,可以配置一级二级三级域名,其中,二三级域名需要到云平台去配置后再在这里配置才可以。
rewrite里的index是表示直接访问配置的域名的时候,后缀加入,例如这里配置为index,则访问baidu.com,会直接跳转到baidu.com/index,如果配置为form,会直接跳转为baidu.com/form。
nginx检测
使用1
nginx -t
检测nginx配置是否有错。
部署
使用1
service nginx reload
比restart平滑。