文章目录
1. 下载及安装过程
如果没有gcc环境,需要安装gcc:
yum install gcc-c++
安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
# 进入文件夹
cd /usr/local
#下载安装包
wget http://Nginx.org/download/Nginx-1.18.0.tar.gz
#解压安装包
tar -xvf Nginx-1.18.0.tar.gz
#解压之后不需要重新命名直接进去解压目录
#进入Nginx-1.18.0目录
cd /usr/local/Nginx-1.18.0
#执行命令
#prefix= 指向安装目录(编译安装)
#conf-path= 指向配置文件(Nginx.conf)
#error-log-path= 指向错误日志目录
#pid-path= 指向pid文件(Nginx.pid)
#http-log-path= 设定access log路径
#with-http_gzip_static_module 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
#with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取Nginx自上次启动以来的工作状态)
#with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
./configure --prefix=/usr/local/Nginx --conf-path=/usr/local/Nginx/conf/Nginx.conf --error-log-path=/usr/local/Nginx/logs/error.log --pid-path=/usr/local/Nginx/logs/Nginx.pid --http-log-path=/usr/local/Nginx/logs/access.log --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module
#执行命令
make
#执行make install命令
make install
#启动Nginx
cd /usr/local/Nginx/sbin
./Nginx
#查看Nginx进程
ps -ef | grep Nginx
#打开阿里云的网路安全组开放80端口
#在浏览器访问服务器ip
#设置开机自动启动
vim /lib/systemd/system/Nginx.service
#按i编辑 把下面复制进去 按esc建 再按shift+:键 wq 保存退出
[Unit]
Description=The Nginx HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
#自己Nginx启动的pid文件自己找到文件目录
PIDFile=/usr/local/Nginx/logs/Nginx.pid
#自己Nginx的启动文件
ExecStartPre=/usr/local/Nginx/sbin/Nginx -t
ExecStart=/usr/local/Nginx/sbin/Nginx
ExecReload=/usr/local/Nginx/sbin/Nginx -s reload
#默认
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#启动
systemctl start Nginx.service
设置开机自启
systemctl enable Nginx.service
#提示
Created symlink from /etc/systemd/system/multi-user.target.wants/Nginx.service to /usr/lib/systemd/system/Nginx.service.
#停止开机自启动
systemctl disable Nginx.service
#查看服务当前状态
systemctl status Nginx.service
#重新启动服务
systemctl reload Nginx.service
#停止服务
systemctl stop Nginx.service
配置Nginx开机自启有两种方案,一种如上面介绍的(推荐);
另一种是vim /etc/rc.d/rc.local
2. 常见报错
2.1 执行make install 报错问题解决make[1]: *** [install] Error 1 make: *** [install] Error 2
可能是相关依赖没有安装,安装依赖后再重新编译
2.2 make[1]: *** [install] Error 1
make[1]: *** [install] Error 1
make[1]: Leaving directory `/usr/local/Nginx'
2.3 启动Nginx服务报错Job for Nginx.service Failed because the control process exited with error code.Nginx使用service Nginx restart报错
启动Nginx服务时如果遇到这个错误 Job for Nginx.service Failed because the control process exited with error code. See “systemctl status Nginx.service” and “journalctl -xe” for details.
可能原因:
3. Nginx的相关命令
- 启动:./sbin/Nginx
- 根据配置文件启动:./sbin/Nginx -c Nginx_vue.conf(默认为Nginx.conf)
- 停止:./sbin/Nginx -s stop
- 退出:./sbin/Nginx -s quit(优雅的停止)
- 重启:./sbin/Nginx -s reopen
- 重新加载配置文件:./sbin/Nginx -s reload
- 测试 Nginx 配置是否有语法错误:./sbin/Nginx -t
- 查看 Nginx 版本:./sbin/Nginx -v
- 查看帮助:./sbin/Nginx -s -h
参考文献:
https://blog.csdn.net/weixin_41400411/article/details/116059479
https://www.cnblogs.com/xxoome/p/5866475.html
https://blog.csdn.net/paralysed/article/details/104162345
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。