nginx-1.12.2编译安装指导

nginx-1.12.2编译安装

  • 下载源码包
  • 安装
  • 安装后配置

下载源码包

下载地址:http://nginx.org/en/download.html

nginx-1.12.2:http://nginx.org/download/nginx-1.12.2.tar.gz


安装

创建nginx worker 用户

groupadd -r www
useradd -r -g www -s /sbin/nologin www
id www

安装前,安装编译环境及依赖包

yum install -y gcc gcc-c++ pcre-devel openssl-devel 

编译选项

./configure \
--prefix=/usr/local/nginx-1.12.2 \
--conf-path=/usr/local/nginx-1.12.2/etc/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=www \
--group=www \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong \
--param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' \
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' \

make
make install

安装后配置

创建 nginx-1.12.2 到 nginx的链接

ln -s /usr/local/nginx-1.12.2 /usr/local/nginx
ls -l |grep nginx

创建配置文件存放目录链接

ln -s /usr/local/nginx/etc /etc/nginx
ls -l /etc/|grep nginx
ls /etc/nginx/

配置nginx启动项

ln -s  /usr/local/nginx/sbin/nginx /usr/sbin/
ls -l /usr/sbin/ |grep nginx
nginx -V

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
 
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
 
[Install]
WantedBy=multi-user.target

编辑配置文件

vim /etc/nginx/nginx.conf

user www;

mkdir -p /var/cache/nginx/client_temp   # 创建缓存目录

防火墙配置

firewall-cmd --add-port=80/tcp --permanent 
firewall-cmd --reload

启动 nginx,并设置开机启动

systemctl start nginx
systemctl enable nginx

测试

浏览器访问 ip地址
或
curl -I <ip>

安装配置nginx完成,之后还需要优化和配置虚拟主机。升级的时候,把新版本的安装目录链接到 /usr/local/nginx 上,再把配置文件拷贝到新版本的安装目录就 ok 了。

rm -f /usr/local/nginx   # 删除原来的链接
ln -s /usr/local/nginx-<version> /usr/local/nginx  # 新建新版本的链接
\cp -r /usr/local/nginx-<old-version>/etc/* /usr/local/gninx/etc/   # 拷贝配置文件到新版本的相应目录下

nginx -V  # 查看版本信息
systemctl restart nginx  # 重启nginx服务 

有疑惑之处请发邮件到下面的邮箱。
2017-11-6 by achxku@163.com

原文链接: https://www.cnblogs.com/xkus/p/7791895.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    nginx-1.12.2编译安装指导

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/262776

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月14日 下午3:23
下一篇 2023年2月14日 下午3:23

相关推荐