LINUX安装NGINX

Linux版本: CentOS 6.5 64位

一. 安装编译工具及库文件

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

二. 安装PCRE,让NGINX支持Rewrite功能

# yum install pcre

三. 安装NGINX

- 3.1 下载NGINX

可在http://nginx.org/en/download.html下载最新版本的NGINX

# wget http://nginx.org/download/nginx-1.13.7.tar.gz

- 3.2 解压

# tar -zxvf nginx-1.13.7.tar.gz

- 3.3 进入安装包目录

# cd nginx-1.13.7

- 3.4 编译安装

# ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module && make && make install && make clean
--with-pcre=/usr/src/pcre-8.21 指的是pcre-8.21 的源码路径。
--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源码路径。

- 3.5 查看安装路径并进入

[root@localhost nginx-1.13.7]# whereis nginx
nginx: /usr/local/nginx
[root@localhost nginx-1.13.7]# cd /usr/local/nginx

- 3.6 启动NGINX

[root@localhost nginx]# sbin/nginx

启动后可在浏览器上访问 host:port,如 127.0.0.1:80 。若打开后出现如下页面则安装完成 
安装完成

四. 安装过程中遇到的问题

- 4.1 使用make编译时报错

提示信息:

在包含自 src/core/ngx_core.h:71 的文件中,
                 从 src/core/nginx.c:9:
src/core/ngx_regex.h:15:18: 错误:pcre.h:没有那个文件或目录
In file included from src/core/ngx_core.h:71,
                 from src/core/nginx.c:9:
src/core/ngx_regex.h:24: 错误:expected specifier-qualifier-list before ‘pcre’

原因及解决方法: 
未安装pcre-devel

# yum install pcre-devel

yum -y install openssl openssl-devel

更改后再次运行出错,提示信息:

cd /srv/pcre2-10.21 \
        && make libpcre.la
make[2]: Entering directory `/srv/pcre2-10.21'
make[2]: *** 没有规则可以创建目标“libpcre.la”。 停止。
make[2]: Leaving directory `/srv/pcre2-10.21'
make[1]: *** [/srv/pcre2-10.21/.libs/libpcre.a] 错误 2
make[1]: Leaving directory `/srv/nginx-1.13.7'

原因及解决方法: 
将pcre安装成了pcre2,NGINX不支持pcre2,换成pcre

- 4.2 启动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()

原因及解决方法: 
NGINX所使用的端口号被占用,默认端口为80,可以在配置文件中修改或者关闭占用端口的进程

NGINX配置文件如下:

[root@localhost conf]# vi nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
"nginx.conf" 117L, 2656C written
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux安装Nginx有几种方法。一种方法是通过包管理器进行安装。您可以使用命令"yum install nginx"来安装最新的稳定版本,默认情况下安装的是Nginx 1.20.2版本。另外一种方法是通过源码编译安装Nginx。这需要下载Nginx安装包并解压缩,然后进行依赖安装和配置。具体步骤如下: 1. 下载Nginx安装包,并解压缩。 2. 安装Nginx的依赖包。 3. 进入解压缩后的Nginx目录,执行"./configure"命令进行配置。 4. 执行"make"命令进行编译。 5. 执行"make install"命令进行安装。 6. 修改Nginx的配置文件"nginx.conf",可以设置用户和用户组等参数。 7. 启动Nginx,可以使用命令"nginx"。 8. 停止或重启Nginx,可以使用命令"nginx -s stop"和"nginx -s reload"。 9. 设置Nginx开机自启动,可以将Nginx添加到系统的启动项中。 10. 配置防火墙,确保80端口开放以允许Nginx的HTTP访问。 根据您的需求和喜好,您可以选择适合您的安装方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Linux安装nginx详细步骤](https://blog.csdn.net/adaizzz/article/details/126669430)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [linux 系统下四种nginx安装方法](https://blog.csdn.net/shallow72/article/details/123878716)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值