linux安装nginx服务

1. 安装源码编译工具及库

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

2. 安装PCRE(Perl)

wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
tar zxvf pcre-8.35.tar.gz
cd ./pcre-8.35
./configure
make&make install
pcre-config --version

3. 下载nginx源码

http://mirrors.sohu.com/nginx/nginx-1.16.0.tar.gz

同上源码安装

tar
cd
configure
make&make install

进入相关路径启动nginx服务

[root@leyshine sbin]# pwd
/usr/local/nginx/sbin
[root@leyshine sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

发生错误!!!端口被占用–HTTPD

[root@leyshine sbin]# netstat -ltnp | grep "80"
tcp6       0      0 :::80                   :::*                    LISTEN      1090/httpd          
[root@leyshine sbin]# kill 1090
[root@leyshine sbin]# ./nginx
[root@leyshine sbin]# ./nginx -v
nginx version: nginx/1.16.1

[root@leyshine sbin]# netstat -ltnp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12908/nginx: master 
[root@leyshine sbin]# ps aux | grep nginx
root     12908  0.0  0.0  20556   612 ?        Ss   07:45   0:00 nginx: master process ./nginx
nobody   12909  0.0  0.0  23092  1388 ?        S    07:45   0:00 nginx: worker process
root     12924  0.0  0.0 112716   960 pts/2    S+   07:46   0:00 grep --color=auto nginx

5 测试打开首页

[root@leyshine /]# curl http://localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

6.开机启动

[root@leyshine system]# pwd
/usr/lib/systemd/system
[root@leyshine system]# vim nginx.service
[root@leyshine system]# cat nginx.service 
[Unit]
Description=nginx
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
[root@leyshine system]# systemctl start nginx
[root@leyshine system]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-02-05 08:13:31 HKT; 12s ago
  Process: 13399 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 13401 (nginx)
    Tasks: 2
   CGroup: /system.slice/nginx.service
           ├─13401 nginx: master process /usr/local/nginx/sbin/nginx
           └─13402 nginx: worker process

Feb 05 08:13:31 leyshine.com systemd[1]: Starting nginx...
Feb 05 08:13:31 leyshine.com systemd[1]: Started nginx.
systemctl enable nginx.service
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值