nginx安装配置

Nginx1.18部署

 

nginx-1.18.0部署

1. 部署前准备


/usr/sbin/groupadd www && /usr/sbin/useradd -g www www && ulimit -SHn 65535 && systemctl disable firewalld.service && systemctl stop firewalld.service

2. 安装依赖程序

yum install -y wget gcc-c++ gcc openssl openssl-devel ncurses ncurses-devel gd gd-devel  perl-CPAN

注:安装依赖程序前,需检查/etc/pki/rpm-gpg/目录下是否有EPEL的认证文件RPM-GPG-KEY-EPEL-7,如果没有此文件,需要下载,命令如下:
yum install -y wget && cd /etc/pki/rpm-gpg/ && wget http://10.0.22.16/epel/RPM-GPG-KEY-EPEL-7

3. 编译安装nginx

#注:若无法镜像仓库中文件,可先在本地下载,再上传至服务器对应目录。


mkdir -p /var/log/nginx /usr/local/nginx/vhosts/ && chmod +w /var/log/nginx && chown -R www:www /var/log/nginx /usr/local/nginx/vhosts/ && cd /tmp && wget http://去官网地址下载/Third-party/nginx-1.18.0/nginx-1.18.0.tar.gz && tar -zxvf nginx-1.18.0.tar.gz

cd /tmp && wget http://去官网地址下载/Third-party/nginx-1.18.0/openssl-1.1.1k.tar.gz && wget http://去官网地址下载/Third-party/nginx-1.18.0/headers-more-nginx-module-0.33.tar.gz && wget http://去官网地址下载/Third-party/nginx-1.18.0/pcre-8.44.tar.gz && tar -zxvf pcre-8.44.tar.gz && tar -zxvf openssl-1.1.1k.tar.gz && tar -zxvf headers-more-nginx-module-0.33.tar.gz

cd /tmp/nginx-1.18.0 && ./configure --user=www --group=www --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_auth_request_module --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gzip_static_module --with-pcre=/tmp/pcre-8.44 --add-module=/tmp/headers-more-nginx-module-0.33 --with-openssl=/tmp/openssl-1.1.1k --with-http_gunzip_module --with-http_sub_module

make && make install

4. 配置启动程序及配置文件


cd /etc/init.d && wget http://去官网地址下载/Third-party/nginx-1.18.0/nginx && chmod +x /etc/init.d/nginx && cd /usr/local/nginx/conf && mv nginx.conf nginx.conf.bak && wget http://去官网地址下载/Third-party/nginx-1.18.0/nginx.conf && service nginx start

5. 部署完成后的说明


完成部署后,根据nginx.conf配置文件中的信息,没有配置web端口信息。如需验证部署结果,需要取消server部分的注释,并修改root路径,修改为/usr/local/nginx/html,或者根据实际需求修改。修改nginx.conf前,需备份此文件。如下截图:

完成操作后,检查nginx配置文件是否正确,最后重启nginx应用。
/usr/sbin/nginx -t #检查配置文件
service nginx restart #重启nginx应用
curl http://localhost:80 #检查nginx启动情况

原文地址:https://www.cnblogs.com/y593216/p/14731556.html