nginx的基础使用
1.nginx的常用命令
start nginx--启动
nginx -t--检查nginx的状态
nginx -s stop--停止nginx
nginx -s reload--重启nginx
2.一般nginx常用于代理,转发跨域问题
server {
listen 3334;
server_name localhost;
location / {
proxy_pass http://localhost:3333;
}
location /api {
proxy_pass http://xxx.com;
}
}这里可以看出来,假如我们本地服务器的端口号是3333
而nginx使用了3334端口来监听,把本地服务以api结尾的请求转发到http://xxx.com去解决跨域问题
列如:本地服务ajax请求,localhost:3333/api/total这个接口,
就会把localhost:3333/api转发成http://xxx.com/total了
即可完美解决本地的跨域问题