Linux下安装nginx教程(Centos7)

1 篇文章 0 订阅

1. 环境及准备

环境:Centos7

准备:确保系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel。
Linux下检查是否安装过某软件包:http://www.cnblogs.com/xxoome/p/5866553.html

# 安装命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

2. 下载安装

# 指定目录下创建nginx目录(我的是/usr/myname/nginx)
mkdir nginx
# 下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
# 解压
tar -zxvf nginx-1.13.7.tar.gz
# 进入nginx目录执行,不加后面的命令会默认给你装到/usr/local/nginx目录下
./configure --prefix=/usr/myname/nginx
# 如果此步报错:c compiler cc is not found,说明是缺少 gcc-c++ 的包,没有则忽略
# 解决办法:
yum -y install gcc-c++
# 执行make命令
make
# 执行make install命令
make install

3. 测试是否安装成功

# cd到刚才配置的安装目录
./sbin/nginx -t
  • 正常情况的信息输出:
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
  • 如果报如下的错,说明nginx安装目录下没有logs文件夹
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
2020/04/04 10:08:56 [emerg] 6996#0: open() "/usr/local/nginx/logs/access.log" failed (2: No such file or directory)
  • 解决办法:
mkdir logs
chmod 700 logs
  • 启动
cd /usr/local/nginx/sbin
./nginx //启动nginx
  • 在浏览器中输入服务器的ip地址,如:192.168.11.12,(默认是80端口),会显示welcome to ngnix。
  • 如果你的80端口被apache占了,你可以在./conf/nginx.conf中修改端口。
server
  {
    listen 80 ;#修改此处为任意端口,访问时访问你的ip:该端口即可
    server_name localhost;#域名
    index index.html index.htm index.php;
    root /usr/local/webserver/nginx/html;#站点目录
      location ~ .*\.(php|php5)?$
    {
      #fastcgi_pass unix:/tmp/php-cgi.sock;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
    {
      expires 30d;
  # access_log off;
    }
    location ~ .*\.(js|css)?$
    {
      expires 15d;
   # access_log off;
    }
    access_log off;
  }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值