安装
- 安装
sudo apt-get update
// 下载安装nginx
sudo apt-get install nginx
2.测试安装
在浏览启输入localhost:

nginx基本操作
// 重启nginx
sudo service nginx restart
// 启动nginx
sudo service nginx start
// 停止nginx
sudo service nginx stop
// 查看进程
ps -ef|grep nginx
nginx配置文件
conf.d
:用户自己定义的conf配置文件sites-available
:系统默认设置的配置文件sites-enabled
:由sites-available
中的配置文件转换生成nginx.conf
:汇总以上三个配置文件的内容 ,同事配置我们所需要的参数
配置nginx
- 在conf.d文件下创建自己的配置文件。例:
myconf.conf
- 在
myconf.conf
中添加
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080
}
# 所有跨域访问以 /api 开头
location /api {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass 你需要代理到的ip地址;
}
}
- 重启nginx
请求
axios({
method:'post',
url:'http://localhost/api/xxxxxxxxx',
})