linux安装nginx步骤

1、安装依赖

yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl-devel 

2、从官网下载对应版本的安装包:nginx: download

3、下载、并安装nginx

//创建一个nginx安装目录
cd /usr/local
mkdir nginx
cd /software/
//下载tar包
wget http://nginx.org/download/nginx-1.22.1.tar.gz
tar -zxvf nginx-1.22.1.tar.gz
cd nginx-1.22.1

//执行命令,考虑到后续安装ssl证书 添加两个模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
//执行make命令
make
//执行make install命令
make install

若执行./configure出现错误:

1. ./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= option 

这个错误是由于您正在尝试编译nginx并启用HTTP重写模块,但系统缺少PCRE库。有几种解决方案可以解决这个问题:
安装系统上的PCRE库。
a.在Ubuntu / Debian上,您可以使用以下命令:

 sudo apt-get install libpcre3 libpcre3-dev
b.在CentOS / RedHat上,您可以使用以下命令安装PCRE:

  sudo yum install pcre pcre-devel
如果您无法在系统上安装PCRE,则可以使用–with-pcre = 选项静态构建PCRE库。将 替换为PCRE源代码的路径。

./configure --with-pcre=/usr/local/src/pcre-8.44
这将在编译期间构建一个静态PCRE库,以便nginx可以使用它以启用HTTP重写模块。

2../configure: error: SSL modules require the OpenSSL library.You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl= option.

这个错误是因为您正在尝试编译nginx并启用SSL模块,但系统缺少OpenSSL库。有几种解决方案可以解决这个问题:

安装系统上的OpenSSL库。

在Ubuntu / Debian上,您可以使用以下命令:

sudo apt-get install libssl-dev

在CentOS / RedHat上,您可以使用以下命令安装OpenSSL:

sudo yum install openssl openssl-devel

如果您无法在系统上安装OpenSSL,可以使用–with-openssl = 选项从源代码构建OpenSSL库。将 替换为OpenSSL源代码的路径。

./configure --with-openssl=/usr/local/src/openssl-1.1.1j

这将在编译期间构建一个静态OpenSSL库以便nginx可以使用它以启用SSL模块。

4、启动nginx

cd /usr/local/nginx/sbin
#指定配置文件启动
./nginx -c  /usr/local/nginx/conf/nginx.conf

5、也可以默认启动:./nginx

6、停止nginx: ./nginx -s stop

7、重启nginx:    ./nginx -s reload

8、在linux任意目录直接使用nginx,提示未找到命令

解决方法:编辑/etc/profile文件,在末尾处添加

export PATH=$PATH:/usr/local/nginx/sbin

9、查看nginx版本号:   /usr/local/nginx/sbin/nginx -V

10、配置信息如下

#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       8888;
        server_name  192.168.5.100;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location /aa/ {
			proxy_pass http://192.168.5.100:8083/;
		}
	
		location / {
			proxy_pass http://192.168.5.100:8083;
		}
        #error_page  404              /404.html;
      
    }
	
    # another virtual host using mix of IP-, name-, and port-based configuration
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
	
    # HTTPS server
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

余额很不足

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值