Linux环境安装配置nginx服务流程
Linux环境的Centos、麒麟、统信操作系统安装配置nginx服务流程操作1、官网下载下载地址或者通过命令下载wget http://nginx.org/download/nginx-1.20.2.tar.gz2、上传到指定的服务器并解压tar -zxvf nginx-1.20.1.tar.gz cd nginx-1.20.1 #有configure 目录3、编译并安装到自定义的路径#可以先创建编译的目录 mkdir nginx # 进入 cd nginx-1.20.1 有configure 目录 ./configure --prefix/usr/local/nginx #初始化安装地址 ## 添加其他原有参数通过 nginx -V 查看 ./configure --with-stream --prefix/usr/local/nginx make #编译 sudo make install #执行1编译报错linux环境编译nginx时报错-bash: ./configure: Permission deniedchmod x ./configure # 为当前目录下的 configure 文件添加可执行权限2编译报错./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcrepath option.解决方案#Ubuntu/Debian apt-get install -y libpcre3 libpcre3-dev #CentOS/RHEL yum install -y pcre pcre-devel3 安装路径/usr/local/nginx可以自定义确定。安装后去confg目录中修改配置文件比如server { listen 8080; server_name localhost; ... }4、启动服务# 即启动sbin/nginx 的命令 sudo /usr/local/nginx/sbin/nginx 或者 sudo ./usr/local/nginx/sbin/nginx 或者进入sbin目录 sudo ./nginx 测试配置语法推荐先校验 ./nginx -t 若测试通过重新加载配置 ./nginx -s reload5、检查是否启动ps aux | grep nginx6、停止服务sudo /usr/local/nginx/sbin/nginx -s stop 进入sbin目录 sudo ./nginx -s stop7、修改后再次启动sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf或者重新加载配置文件达到平滑重启sudo /usr/local/nginx/sbin/nginx -s reload8、没有修改权限问题解决方案通过管理员用户给其他用户分配权限#更改目录所有者 sudo chown nandao /usr/local/nginx #该单个首层目录权限 sudo chmod 775 /usr/local/nginx #修改目录及其子目录权限 sudo chmod -R 775 /usr/local/nginx #为所有用户添加执行权限报错内容 nginx -V查看 nginx版本信息时报错-bash: #/usr/local/soft/front/new/nginx/sbin/nginx: Permission denied chmod x /usr/local/new/nginx/sbin/nginx9、查看版本号nginx -v #提供了比-v命令更详细的信息 nginx -V #进入sbin目录查询 ./nginx -v结果截图如果nginx -v 查看版本时时报错内容如下 -bash: nginx未找到命令 解决方案如下原因未配置环境变量:将nginx的可执行文件路径添加到环境变量PATH中可以通过编辑 vi 或者 vim /etc/profile文件或当前用户的\~/.bashrc文件来添加环境变量。在文件的末尾添加如下行假设nginx的可执行文件路径为/usr/local/nginx/sbin/export PATH$PATH:/usr/local/nginx/sbin/保存文件后执行source /etc/profile或source \~/.bashrc使更改生效 。10、服务开机启动设置vim /etc/systemd/system/nginx.service [Unit] DescriptionNginx HTTP Server Afternetwork.target [Service] Typeforking ExecStart/usr/local/nginx/sbin/nginx ExecStop/usr/local/nginx/sbin/nginx -s stop ExecReload/usr/local/nginx/sbin/nginx -s reload Restarton-failure RestartSec5 Userroot Grouproot [Install] WantedBymulti-user.target这里也要同步更新修改。安装报错其他问题的解决方案参考参考2其他环境安装参考如下ubuntu环境安装配置nginx流程到此linux环境安装完成后面会分享容器环境安装nginx步骤敬请期待