& nginx代理
Windows下载地址:
http://nginx.org/en/download.html
Linux下载地址:
https://nginx.org/download/
1. Windows下安装使用
1)下载后解压
2)nginx配置
-
conf
文件夹下的nginx.conf
即为配置文件;
在记事本或其他IDE工具中打开,在http { }
里配置server
:
server {
listen 80; # 监听的端口号
server_name localhost; # 监听的ip,可写具体的ip地址;localhost表示监听nginx所在服务器ip
# 代理默认路径
location / {
root /project/html/dist;; # root配置需要代理的页面路径
index index.html index.htm; # 代理的页面文件
}
# 代理 /api 路径:调后端接口时设置代理可解决跨域问题
location /api {
# 把路径中的 http://localhost:80/api 替换为 http://test:8090
proxy_pass http://test:8090;
}
}
3)nginx常用命令
- 在
nginx
根目录下运行
启动命令: start nginx或nginx.exe
停止命令: nginx.exe -s stop # stop是快速停止nginx,可能并不保存相关信息
退出命令: nginx.exe -s quit # quit是完整有序的停止nginx,并保存相关信息
重新载入: nginx.exe -s reload
重新打开日志: nginx.exe -s reopen
查看Nginx版本: nginx -v
2. Linux下安装使用
1)下载后解压
解压命令:tar -zxvf nginx-0.1.0.tar.gz
2)nginx配置
-
conf
文件夹下的nginx.conf
即为配置文件:
cd conf
通过vi nginx.conf
查看配置;
接着按i
进入编辑状态;
在http { }
里配置server
【配置内容同上】;
esc
退出编辑状态;
:wq
退出保存;
3)nginx常用命令
- 在
nginx/sbin
目录下运行
启动命令: ./nginx
停止命令: ./nginx -s stop # stop是快速停止nginx,可能并不保存相关信息
退出命令: ./nginx -s quit # quit是完整有序的停止nginx,并保存相关信息
重新载入: ./nginx -s reload
重新打开日志: ./nginx -s reopen
查看Nginx版本: ./nginx -v