ubuntu最详细安装nginx_ubuntu centos debian

ubuntu最详细安装nginx_ubuntu centos debian1、创建nginx账号root@ubuntu:/usr#useradd-mnginx

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

1、创建nginx账号

root@ubuntu:/usr# useradd -m nginx
root@ubuntu:/usr# passwd nginx
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@ubuntu:/usr# su nginx
# 为nginx添加bash权限,默认为sh
vi /etc/passwd

# 修改如下/bin/bash
nginx:x:1001:1001::/home/nginx:/bin/bash

2、创建nginx工作目录

nginx@ubuntu:/$ cd /usr/local/
nginx@ubuntu:/$ sudo mkdir nginx
nginx@ubuntu:/$ sudo chown nginx:nginx nginx/
nginx@ubuntu:/$ cd nginx
nginx@ubuntu:/usr/local/nginx$ wget http://nginx.org/download/nginx-1.21.0.tar.gz
--2021-06-07 01:18:15--  http://nginx.org/download/nginx-1.21.0.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1063682 (1.0M) [application/octet-stream]
Saving to: ‘nginx-1.21.0.tar.gz’

nginx-1.21.0.tar.gz                        100%[======================================================================================>]   1.01M   188KB/s    in 5.5s    

2021-06-07 01:18:22 (188 KB/s) - ‘nginx-1.21.0.tar.gz’ saved [1063682/1063682]

nginx@ubuntu:/usr/local/nginx$ tar -zxf nginx-1.21.0.tar.gz 

nginx@ubuntu:/usr/local/nginx$ cd nginx-1.21.0/

3、准备nginx 环境

#解决依赖包openssl安装
sudo apt-get install openssl libssl-dev

#解决依赖包pcre安装
sudo apt-get install libpcre3 libpcre3-dev

#解决依赖包zlib安装
sudo apt-get install zlib1g-dev

 4、编译nginx 

nginx@ubuntu:/usr/local/nginx/nginx-1.21.0$ ./configure 
nginx@ubuntu:/usr/local/nginx/nginx-1.21.0$ make
nginx@ubuntu:/usr/local/nginx/nginx-1.21.0$ make install

5、启动nginx

#需使用root账号启动,否则报  Permission denied
nginx@ubuntu:/usr/local/nginx/$ sudo ./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

6、检查状态

nginx@ubuntu:/usr/local/nginx/sbin$ ps -aux | grep nginx

root      19782  0.0  0.0  25212   412 ?        Ss   01:45   0:00 nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.conf
nobody    19783  0.0  0.0  30040  2960 ?        S    01:45   0:00 nginx: worker process
nginx     19801  0.0  0.0  46780  3520 pts/0    R+   01:47   0:00 ps -aux
nginx     19802  0.0  0.0  21544  1012 pts/0    S+   01:47   0:00 grep --color=auto nginx

7、测试访问

curl http://localhost

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

8、使用nginx 命令

# 提示命令不存在
root@ubuntu:/usr/local/nginx# nginx -t

Command 'nginx' not found, but can be installed with:


# 添加环境变量
root@ubuntu:/usr/local/nginx# vim /etc/profile

# 在最后追加
NGINX_HOME=/usr/local/nginx/sbin
export PATH=$NGINX_HOME:$PATH

# source /etc/profile  使配置文件立即生效
root@ubuntu:/usr/local/nginx# source /etc/profile 

# 成功
root@ubuntu:/usr/local/nginx# 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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/191818.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Network 之二 Ethernet(以太网)中的 MAC、MII、PHY 详解[通俗易懂]

    Network 之二 Ethernet(以太网)中的 MAC、MII、PHY 详解[通俗易懂]结构  从硬件的角度看,以太网接口电路主要由MAC(MediaAccessControl)控制器和物理层接口PHY(PhysicalLayer,PHY)两大部分构成。如下图所示  但是,在实际的设计中,以上三部分并不一定独立分开的。由于,PHY整合了大量模拟硬件,而MAC是典型的全数字器件。考虑到芯片面积及模拟/数字混合架构的原因,通常,将MAC集成进微控制器而将PHY留在片外…

    2022年9月22日
    2
  • Java 工厂模式

    Java 工厂模式简单工厂模式详解简单工厂模式用来定义一个工厂类,它可以根据参数的不同返回不同类的实例,被创建的实例通常都具有共同的父类。因为在简单工厂模式中用于创建实例的方法是静态方法,因此简单工厂模式又被称为静态工厂方法模式,它属于类创建型模式。简单工厂模式的要点在于,当我们需要什么,只需要传入一个正确的参数,就可以获取我们所需要的对象,而无需知道其创建细节。简单工厂模式结构比较简单,其核心是工厂类的设计,其机构如图所示:在简单工厂模式结构图中包含如下几个角色。Factory(工厂角色):工厂角色即工厂类,它

    2022年7月20日
    21
  • pycharm社区版激活码【在线注册码/序列号/破解码】

    pycharm社区版激活码【在线注册码/序列号/破解码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月20日
    48
  • 【汇编语言】(x86)test与跳转指令(je jle jge jg jl……)组合的含义

    【汇编语言】(x86)test与跳转指令(je jle jge jg jl……)组合的含义在x86指令集中,经常遇到text指令与条件跳转指令组合,这是什么含义呢?博主表示,查了很多资料也没人完全说清楚……这里只用最简单的,抽象层次进行说明,不讲原理。举例text edx,edxjle 某地址含义是:如果edx<=0,就跳到某地址,否则继续往下执行。jle换成jg的话,就是edx>0跳转。其他同理。与cmp指令和跳转指令组合的区别是:这个组合比较的是cmpA,B中,A与B的关系。而textA,A则比较的是A与0的关系。这些都是抽象层次的应

    2025年6月25日
    4
  • Drupal 安装「建议收藏」

    Drupal 安装「建议收藏」2.Drupal安装在安装Drupal前,你需要在服务器上先搭建一个PHP+MySQL环境。专业网站一般是安装LAMP(Linux+Apache+MySQL+PHP)。环境的搭建可参考如下文章:Windows下php服务器配置过程:http://www.loosky.net/?q=node/25Linux下Lamp服务器的配置:http://www…

    2022年7月20日
    14
  • vlan的原理和作用_生态因子作用的基本原理

    vlan的原理和作用_生态因子作用的基本原理相关名词:VirtualLocalAreaNetwork—VLAN、VirtualPrivateNetwork—VPN、VirtualRedundancyProtocol—VRRP等。一。VLAN的作用1.把一个广播帧所能到达的整个范围称为二层广播域,简称广播域。显然,一个交换网络其实就是一个广播域。在该网络中,假定PC0向PC10发送一个单播帧Y…

    2022年8月10日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号