笔记贴 记录下nginx相关的知识点
1.启动
- 注意:路径不要用中文名 否则启动不了
- 如果是启动dist文件就把dist里面的文件拷贝到文件夹html里 并且在nginx.config文件配置后指向 root后面跟上html
例如:
location / {
root html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
- 打开conf里面nginx.conf文件修改端口等一些配置项
- 在nginx.exe对应的文件夹cmd,然后输入nginx.exe执行
浏览器打开配置的端口就能浏览了 比如localhost:8083
2.关闭
windows关闭打开的nginx只能杀死进程 在任务管理器搜nginx并结束进程
3.重定向
修改nginx.conf里面的配置项 指向重定向的地址 屏蔽之前指向的静态文件
示例:
需求:启动后输入地址localhost:8083自动转到http://120.621.168.100:8083
server {
listen 8083;
server_name localhost;
location / {
rewrite ^/(.*)$ http://120.621.168.100:8083/$1 permanent;
# root html/;
# index index.html index.htm;
# try_files $uri $uri/ /index.html;
}
}