下载安装链接
nginx(NGINX)详细下载安装及使用教程(非常适合入门)_nginx下载-CSDN博客
- # 前往用户根目录
- cd ~
-
- #下载nginx1.13.7
- wget http://nginx.org/download/nginx-1.13.7.tar.gz
-
- #解压安装包
- tar -xf nginx-1.13.7.tar.gz
-
- #进入目标文件
- cd nginx-1.13.7
-
- # 配置安装路径:/usr/local/nginx
- ./configure --prefix=/usr/local/nginx
-
- #编译并安装
- make && make install
-
- # 建立软连接:终端命令 nginx
- ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
-
- #删除安装包与文件:
- cd ~
- rm -rf nginx-1.13.7
- rm -rf nginx-1.13.7.tar.xz
-
- # 测试Nginx环境,服务器运行nginx,本地访问服务器ip
- nginx # 启动nginx服务,监听80端口----》公网ip 80 端口就能看到页面了
- 服务器绑定的域名 或 ip:80
-
- # 静态文件放的路径
- /usr/local/nginx/html
-
- # 查看进程
- ps aux | grep nginx
- nginx -t 检查配置文件是否有语法错误
- nginx -s reload 热加载,重新加载配置文件
- nginx -s stop 快速关闭
- nginx -s quit 等待工作进程处理完成后关闭
- 复制代码
-
- systemctl start nginx # 启动 Nginx
- systemctl stop nginx # 停止 Nginx
- systemctl restart nginx # 重启 Nginx
- systemctl reload nginx # 重新加载 Nginx,用于修改配置后
- systemctl enable nginx # 设置开机启动 Nginx
- systemctl disable nginx # 关闭开机启动 Nginx
- systemctl status nginx # 查看 Nginx 运行状态
- # 工作进程的数量
- worker_processes 1;
- events {
- worker_connections 1024; # 每个工作进程连接数
- }
-
- http {
- include mime.types;
- default_type application/octet-stream;
-
- # 日志格式
- log_format access '$remote_addr - $remote_user [$time_local] $host "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for" "$clientip"';
- access_log /srv/log/nginx/access.log access; # 日志输出目录
- gzip on;
- sendfile on;
-
- # 链接超时时间,自动断开
- keepalive_timeout 60;
-
- # 虚拟主机
- server {
- listen 8080;
- server_name localhost; # 浏览器访问域名
-
- charset utf-8;
- access_log logs/localhost.access.log access;
-
- # 路由
- location / {
- root www; # 访问根目录
- index index.html index.htm; # 入口文件
- }
- }
-
- # 引入其他的配置文件
- include servers/*;
- }