linux安装nginx

基础环境:CentOS8.0、Nginx1.19.9.

一.安装nginx前的准备工作

在linux下安装nginx,首先需要安装 gcc-c++编译器。然后安装nginx依赖的pcre和zlib包。最后安装nginx即可。(有很多同学直接下载nginx开始安装,出现各种错误!)

二.安装gcc-c++编译器

[root@hecs-401441 ~]# yum install gcc-c++
[root@hecs-401441 ~]# yum install -y openssl openssl-devel

三.安装pcre包

[root@hecs-401441 ~]# yum install -y zlib zlib-devel
[root@hecs-401441 nginx-1.19.9]# yum -y install pcre-devel

安装完以后下面进行nginx的安装!

四.nginx的下载

下载有2种方式:

1. 在liunx用命令下载(这里我下载的是1.19.9版本的)liunx要能访问外网;

2.从官网下载安装包通过ftp上传;

[root@hecs-401441 ~]# wget https://nginx.org/download/nginx-1.19.9.tar.gz
--2022-11-02 10:42:50--  https://nginx.org/download/nginx-1.19.9.tar.gz
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1060580 (1.0M) [application/octet-stream]
Saving to: ‘nginx-1.19.9.tar.gz’

nginx-1.19.9.tar.gz                           100%[=================================================================================================>]   1.01M  1.38MB/s    in 0.7s    

2022-11-02 10:42:52 (1.38 MB/s) - ‘nginx-1.19.9.tar.gz’ saved [1060580/1060580]

[root@hecs-401441 ~]# ls
mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz  nginx-1.19.9.tar.gz  xxl-job-admin-2.4.0-SNAPSHOT.jar
[root@hecs-401441 ~]# 

下载或者你上传的位置在哪里都可以,后面根据自己的需要把安装包解压到合适的文件夹里面 :

[root@hecs-401441 ~]# ls
mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz  nginx-1.19.9.tar.gz  xxl-job-admin-2.4.0-SNAPSHOT.jar
[root@hecs-401441 ~]# cp nginx-1.19.9.tar.gz /usr/local
[root@hecs-401441 ~]# ls
mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz  nginx-1.19.9.tar.gz  xxl-job-admin-2.4.0-SNAPSHOT.jar
[root@hecs-401441 ~]# cd /usr/local
[root@hecs-401441 local]# ls
bin  etc  games  hostguard  include  lib  lib64  libexec  mysql  nginx-1.19.9.tar.gz  sbin  share  src  uniagent
[root@hecs-401441 local]# 

五.安装nginx

5.1解压nginx安装包

[root@hecs-401441 local]# tar -zxvf nginx-1.19.9.tar.gz

5.1.1 cd到你刚解压的目录里面 

[root@hecs-401441 local]# cd nginx-1.19.9

 5.1.2 进入到nginx-1.19.9目录,输入下面命令,使用nginx默认的配置

[root@hecs-401441 nginx-1.19.9]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@hecs-401441 nginx-1.19.9]# ./configure

5.1.3编译安装(按照顺序执行下面2个命令)

[root@hecs-401441 nginx-1.19.9]# make
[root@hecs-401441 nginx-1.19.9]# make install

5.1.4编译安装完成后 输入下面命令查看自己的nginx安装在哪里。 

[root@hecs-401441 nginx-1.19.9]# whereis nginx
nginx: /usr/local/nginx
[root@hecs-401441 nginx-1.19.9]# 

 5.1.5根据上面获得的目录cd进入sbin目录里面。输入下面命令启动nginx

[root@hecs-401441 nginx-1.19.9]# cd ..
[root@hecs-401441 local]# ls
bin  etc  games  hostguard  include  lib  lib64  libexec  mysql  nginx  nginx-1.19.9  nginx-1.19.9.tar.gz  sbin  share  src  uniagent
[root@hecs-401441 local]# cd nginx
[root@hecs-401441 nginx]# ls
conf  html  logs  sbin
[root@hecs-401441 nginx]# cd sbin/
[root@hecs-401441 sbin]# ls
nginx
[root@hecs-401441 sbin]# ./nginx
[root@hecs-401441 sbin]# 

5.1.6 查看是否启动成功

[root@hecs-401441 sbin]# ps -ef | grep nginx
root       71766       1  0 11:00 ?        00:00:00 nginx: master process ./nginx
nobody     71767   71766  0 11:00 ?        00:00:00 nginx: worker process
root       71796   67846  0 11:00 pts/0    00:00:00 grep --color=auto nginx
[root@hecs-401441 sbin]# 

六.安装完毕

在浏览器输入自己的IP就可以访问nginx了。

配置nginx.conf:

   server {
    listen       20000;
client_max_body_size 50m;
    # server_name  aa;
    # rewrite ^(.*)$ https://${server_name}$1 permanent;
    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /alidata1/services/www/wwwroot/manage/vue;
    try_files $uri $uri/ /index.html;
        index  index.html index.htm;
    }

location /api/ {
        proxy_pass http://127.0.0.1:19999/api/;

    }
    location /group1/ {
	proxy_pass http://127.0.0.1:19999/group1/;
}

}

 注意:

如果访问不了!就是你的服务器防火墙没有开放80端口!(默认监听80端口)

防火墙开放端口

 #查看开放了哪些服务端口

firewall-cmd --list-all

#开放端口号命令

firewall-cmd --add-port=80/tcp --permanent

#重启防火墙,使配置生效

systemctl restart firewalld.service

 

 

 

 

 

  • 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
发出的红包

打赏作者

Angus sonder

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

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

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

打赏作者

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

抵扣说明:

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

余额充值