centos7下安装开源nginx

# nginx开源版本安装

## 虚拟机备份 
### 关闭虚拟机 init 0
### 克隆虚拟机 

## 下载nginxk开源版
wget https://nginx.org/download/nginx-1.25.2.tar.gz

## 安装nginx
tar zxvf nginx-1.25.2.tar.gz 
cd nginx-1.25.2

## 安装nginx到/usr/local/nginx下
[root nginx-1.25.2] ./configure --prefix=/usr/local/nginx

### 安装gcc依赖
[root nginx-1.25.2] ./configure --prefix=/usr/local/nginx
./configure: error: C compiler cc is not found

[root nginx-1.25.2]# yum install -y gcc

### 安装pcre依赖
[root nginx-1.25.2] ./configure --prefix=/usr/local/nginx
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

[root nginx-1.25.2]# yum install -y pcre pcre-devel

### 安装zlib依赖
[root nginx-1.25.2] ./configure --prefix=/usr/local/nginx
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

[root nginx-1.25.2]# yum install -y zlib zlib-devel


### 成功安装
[root nginx-1.25.2] ./configure --prefix=/usr/local/nginx

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

### 根据Makefile编译运行
[root nginx-1.25.2]# cat Makefile 

default:    build

clean:
    rm -rf Makefile objs

.PHONY:    default clean

build:
    $(MAKE) -f objs/Makefile

install:
    $(MAKE) -f objs/Makefile install

modules:
    $(MAKE) -f objs/Makefile modules

upgrade:
    /usr/local/nginx/sbin/nginx -t

    kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
    sleep 1
    test -f /usr/local/nginx/logs/nginx.pid.oldbin

    kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

.PHONY:    build install modules upgrade 
[root nginx-1.25.2] make               ## 根据Makefile编译
[root nginx-1.25.2] make install       ## 编译后执行安装

## 启动nginx
[root nginx-1.25.2] cd /usr/local/nginx/sbin
[root@iZbp195d6ax86t20fssqyjZ sbin]# ll
total 3840
-rwxr-xr-x 1 root root 3930088 Aug 28 14:27 nginx
[root@iZbp195d6ax86t20fssqyjZ sbin]# ./nginx 


## 安装nginx系统服务

### 创建服务脚本
vi /usr/lib/systemd/system/nginx.service

### 服务脚本内容
[Unit]
Description=nginx -  web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

### 重新加载系统服务
systemctl daemon-reload

### 停止原来启动的nginx
[root sbin]# ./nginx -s stop
[root sbin]# ps -ef | grep nginx
root     25580 24790  0 14:49 pts/0    00:00:00 grep --color=auto nginx

### 启动nginx服务
[root sbin]# systemctl start nginx.service

### 查看启动状态
[root sbin]# systemctl status nginx.service

### 开启启动nginx服务
[root sbin]# systemctl enable nginx.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

### 解决网页中文乱码
[root@iZbp195d6ax86t20fssqyjZ conf]# vim nginx.conf
    server {
        listen       80;
        server_name  localhost;

        charset utf-8;   ## 字符集改成utf-8
[root@iZbp195d6ax86t20fssqyjZ sbin]# ./nginx -s reload

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
nginx是一个流行的开源Web服务器软件。根据引用,我们可以看到如何在CentOS系统上安装nginx。首先,需要将下载好的压缩包上传到指定目录并解压。然后,根据引用中的配置文件示例,我们可以创建一个nginx的系统服务脚本,并设置nginx的启动和自启动方式。最后,可以使用系统命令systemctl来管理nginx的启动、止和状态查看。根据引用中的示例,我们可以通过执行`systemctl start nginx.service`来启动nginx服务,通过执行`systemctl enable nginx.service`来设置nginx开机自启,通过执行`systemctl status nginx.service`来查看nginx服务的状态。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Centos7下部署nginx(三种方式安装部署,图文结合超详细,适合初学者)](https://blog.csdn.net/huz1Vn/article/details/129844471)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [centos安装、配置、自启nginx(超详细)](https://blog.csdn.net/qq_39187538/article/details/126525554)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值