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)
上一篇 2026年1月24日 下午7:43
下一篇 2026年1月24日 下午8:15


相关推荐

  • 西门子scl语言运算符_西门子烤箱怎么设置语言中文

    西门子scl语言运算符_西门子烤箱怎么设置语言中文软硬件平台软件是博图TIAv15,硬件是西门子300系列PLC简介使用scl语言编写一个FC子程序,对模拟量进行处理,对模拟数据进行转换。详细介绍添加新块,添加一个FC块,语言选择scl添加变量,输入型变量5个,一个运算后输出变量,3个中间变量,用于计算,存放中间计算结果,IF#in<=#i_minTHEN//判断输入值是否低于模拟量设定下限值#out:=#r_min;//输出直接为浮点数设定值下限END_IF;IF#in&gt

    2026年4月16日
    7
  • win2008 R2 remoteapp

    win2008 R2 remoteapp

    2021年8月14日
    54
  • 当锚点遇到fixed定位

    当锚点遇到fixed定位简介 当点击页面的锚点时会跳转到指定 id 的元素 而实际表现的是滚动条滚动使指定 id 元素对齐滚动条所处元素的 顶端 如果当页面上方出现 fixed 定位时 将会出现锚点定位不准确的情况 1 问题重现当使用锚点时 页面上方存在 fixed 定位 将会出现如下情况 点击 目录二 对应跳转 内容二 的锚点 DOCTYPEhtmlh

    2026年3月17日
    2
  • 23种设计模式总结

    23种设计模式总结一 什么是设计模式设计模式 Designpatter 是一套被反复使用 多数人知晓的 经过分类编目的 代码设计经验的总结 使用设计模式是为了可重用代码 让代码更容易被他人理解 保证代码可靠性 毫无疑问 设计模式于己于他人于系统都是多赢的 设计模式使代码编制真正工程化 设计模式是软件工程的基石 如同大厦的一块块砖石一样 项目中合理的运用设计模式可以完美的解决很多问题 每种模式在现在中都有相应的原理来与之对应 每一个模式描述了一个在我们周围不断重复发生的问题 以及该问题的核心解决方案 这也是它能被广泛

    2026年3月19日
    2
  • 华为交换机关闭网口_华为交换机关闭端口号[通俗易懂]

    华为交换机关闭网口_华为交换机关闭端口号[通俗易懂]华为交换机为VLAN使用中某端口的关闭(在线等啊!!!!急)这里交换机是通过动作来保护非法接入,比如:当一台交换机端口进行mac绑定后,则只允许该mac的PC上网,如果发现其他的mac出现在这个端口上,交换机会认为这个端口被非法接入了,这时就会执行了设置好的一个安全保护动作。默认的这个动作是shutdown,你很可能就是端口被自动shutdown了华为交换机关闭135端口答:通过displayv…

    2022年7月20日
    37
  • ResNet详细解读

    ResNet详细解读这篇文章是DeepResidualLearningforImageRecognition的翻译,精简部分内容的同时补充了相关的概念,如有错误,敬请指正。

    2022年5月25日
    45

发表回复

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

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