Ubuntu 安装Nginx(详细)

Ubuntu 安装Nginx(详细)1 创建 nginx 账号 root ubuntu usr useradd mnginx

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:  (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 [/] 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/233476.html原文链接:https://javaforall.net

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


相关推荐

  • 时间控件(选择时间范围的插件)「建议收藏」

    时间控件(选择时间范围的插件)「建议收藏」后台开发,一般都是有筛选条件的查询,那么问题就来了,根据日期范围搜索的情况下,插件要怎么选????Laydate时间控件这个是最开始,我采用的是两个时间插件,其他也没啥,就是运营部门使用起来可能感觉太麻烦,为啥不能一次让我选了,还有说老是忘记选择结束时间,然后就有了我接下来的工作。。。在此,给大家推荐一款很好使用的日期与时间组件…

    2022年5月10日
    37
  • java策略模式例子_java 登录场景 策略模式

    java策略模式例子_java 登录场景 策略模式Java的策略模式中体现了两个非常基本面向对象的原则-封装变化的概念-编程中使用接口,而不是对接口的实现策略模式的定义定义一组算法,将每个算法都封装起来,并且使它们之间可以互换。策略模式使这些算法在客户端调用它们的时候能够互不影响的变化策略模式的组成抽象策略角色–策略类,通常由一个接口或者抽象类实现具体策略角色–包装了相

    2022年9月4日
    2
  • 斗战神 拳猴刷图加点

    斗战神 拳猴刷图加点是输出手法,我觉得这个一般来说争议不大,但是很重要一点,BOSS战开始前,一定保证身上有一个蛮横的BUFF,如上图所示。至于顺序分别是:九豆或满豆起手-乱星舞-八荒-极影腿×2-巨猿-神行-

    2022年7月2日
    20
  • js生成日历(php编写一个月的日历)

    <!DOCTYPEhtml><html> <head> <metacharset=”utf-8″> <title></title> <styletype=”text/css”> .main{ width:800px; margin:0auto; } …

    2022年4月18日
    42
  • 了解DeepFakes背后的技术

    了解DeepFakes背后的技术1.神经网络和自动编码器简介神经网络概论在计算机科学中,人工神经网络由成千上万个以特定方式连接的节点组成。节点通常分层排列;它们的连接方式决定了网络的类型,最终决定了网络在另一网络上执行特定计算任务的能力。传统的神经网络可能看起来像这样:输入层中的每个节点(或人工神经元)都包含一个数值,该数值对我们要馈送到网络的输入进行编码。如果我们要预测明天的天气,则输入节点可能包含以范围内的数字编码的压力,温度,湿度和风速\left[-1,+1\right]。这些值被广播到下一层。有趣的是,每个边缘

    2022年5月25日
    39
  • Web中常用的Javascript技巧(1)「建议收藏」

    Web中常用的Javascript技巧(1)

    2022年3月8日
    35

发表回复

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

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