1.下载
2.上传
3.解压
# 进入 nginx 压缩包所在目录
cd nginx/ 压缩包所在目录
# 解压
tar -zxvf nginx-1.22.1.tar.gz
4.安装nginx相关依赖
安装nginx的相关依赖:
cd nginx-1.22.1
yum -y install gcc zlib zlib-devel pcre-devel ope nssl openssl-devel
5.生成makefile可编译文件
# 执行configure脚本,设置安装nginx的初始化配置(--with-http_ssl_module:启动 SSL 的支持),生成 Makefile 可编译文件
./configure --with-http_ssl_module
6.编译和安装
// 编译
make
7.nginx安装
# 安装
make install
默认安装路径(/usr/local/nginx)
8.启动nginx
# 进入 nginx 安装目录下的sbin目录
cd nginx 安装目录(默认 /usr/local/nginx/sbin)
执行 nginx 脚本,启动 nginx 服务:
# 执行脚本启动 nginx 服务
./nginx
查看 nginx 执行:
查看 nginx 进程:
ps -ef | grep nginx
# 查看 进程id 所占用的端口号
netstat -nap | grep 进程id
nginx 服务默认占用的是 80 端口
9.查看已开放端口
sudo firewall-cmd --zone=public --list-ports
已近开放了,如果没开放需要进行开放:
# 开放 80 端口
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
开放后,还需要重启防火墙才能生效
10.重启防火墙
sudo firewall-cmd --reload
11.查询nginx是否启动
ps aux|grep nginx
12.查找nginx所在的路径
whereis nginx
which nginx
13.停止nginx服务
./nginx -s stop
14.检查配置是否合法
用于在修改配置后检查下配置是否合法
./nginx -t
15.nginx的配置文件
查看配置文件的内容:
cat conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80; # 默认在80端口启动nginx
server_name localhost; # 绑定的域名
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; # 服务器内部错误
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
16.vi命令修改index.html文件
vi html/index.html #修改
insert 按钮可以进行修改
esc 取消修改
:q 直接退出
:wq 保存退出