Nginx编译安装

编译安装

编译安装Nginx:

**系统:**CentOS-7.5
**软件:**Nginx-1.14.2

**IP地址:**10.0.0.10

下载源码包:点击下载

安装依赖包:
yum -y install pcre* openssl-devel

创建目录:
mkdir /home/tools && cd /home/tools

创建用户:
useradd nginx -s /sbin/nologin -M

解压源码包:

wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar zxf nginx-1.14.2.tar.gz && cd nginx-1.14.2/

预编译:

./configure --prefix=/usr/local/nginx-1.14.2 \
--with-http_ssl_module --with-http_stub_status_module \
--with-http_stub_status_module --with-pcre \
--with-http_realip_module

编译:

make && make install && echo $?
ln -s /usr/local/nginx-1.14.2 /usr/local/nginx

检测是否安装成功:

/usr/local/nginx/sbin/nginx -t        --------->输入命令查看nginx版本

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

备份并修改配置文件:
cd /usr/local/nginx/conf/ && cp nginx.conf nginx.conf.bak && vim nginx.conf

user  nginx;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for" ';
    access_log  logs/access.log  main;

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

加入systemd管理:
vim /etc/systemd/system/nginx.service

[Unit]
Description=nginx server daemon
Documentation=man:nginx(8)
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
systemctl daemon-reload

启动Nginx:
systemctl start nginx
systemctl enable nginx

默认站点目录:
cd /usr/local/nginx/html/

浏览器访问:

systemctl start nginx
systemctl enable nginx

默认站点目录:
cd /usr/local/nginx/html/

浏览器访问:

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值