nginx使用入门使用:
相关命令:
systemctl start nginx.service
service nginx start
systemctl status nginx.service
service nginx status
systemctl restart nginx.service
service nginx restart
systemctl restart nginx.service
service nginx restart
- 每次修改了配置文件nginx.conf,尽量重新加载:
sudo nginx -s reload
- 可以使用命令查看某个端口是否被使用,比如80端口:
nc -zv localhost 80
编译nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
常见用法(太懒了,直接把up主视频中的笔记搞过来):
①反向代理
②负载均衡
个人nginx配置(参考):
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#负载均衡
#①weight:权重
upstream demo{
server 127.0.0.1:8081 weight=10;
server 127.0.0.1:8082 weight=1;
}
server {
listen 80;
server_name localhost;
#代理目标
location / {
proxy_pass http://demo/;
}
}
}
配置后记得重启nginx:
systemctl restart nginx.service
service nginx restart
每次修改了配置文件nginx.conf,尽量重新加载:
nginx -s reload