nginx安装配置

2021/5/6 7:29:05

本文主要是介绍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启动情况

 



这篇关于nginx安装配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程