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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 安卓永久修改像素密度[通俗易懂]

    安卓永久修改像素密度[通俗易懂]adb打开/system/build.prop文件,调整ro.sf.lcd_density这个变量的值,就可以调整像素密度了

    2022年6月6日
    93
  • Android APK 签名校验[通俗易懂]

    Android APK 签名校验[通俗易懂]非对称加密算法非对称加密算法需要两个密钥:公开密钥(简称公钥)和私有密钥(简称私钥)。公钥与私钥是一对,如果用公钥对数据进行加密,只有用对应的私钥才能解密;如果用私钥对数据进行加密,那么只有用对应的公钥才能解密。因为加密和解密使用的是两个不同的密钥,所以这种算法叫作非对称加密算法。非对称加密算法是数字签名和数字证书的基础,大家非常熟悉的RSA就是非对称加密算法的一种实现。消息摘要算

    2022年5月29日
    421
  • 读秒计时器_countdown怎么读

    读秒计时器_countdown怎么读CountDownTimertimer=newCountDownTimer(5*1000,1000){@OverridepublicvoidonTick(longmillisUntilFinished){tv.setText(“还剩”+millisUntilFinished/10…

    2022年9月18日
    1
  • FFmpeg从入门到精通(一)

    FFmpeg从入门到精通(一)FFmpeg介绍FFmpeg既是一种音视频编解码工具,也是一组音视频解码开发套件。作为编解码开发套件,它为开发者提供了丰富的音视频处理的调用接口。FFmpeg基本组成先看图,再看字。FFmpeg的封装模块AVFormatAVFormat中实现了目前多媒体领域中大多数媒体封装格式,包括封装和解封装,如:MP4,FLV等文件封装格式、HTTP,RTMP,HLS等网络协议封装格式。FFm…

    2022年6月26日
    19
  • windows10安装cuda anaconda_电脑自带cuda吗

    windows10安装cuda anaconda_电脑自带cuda吗cuda10.2安装前言下载cuda10.2和cudnn查看本机驱动版本安装过程安装cudnn验证前言tensorflow1.12之后gpu使用cuda10.0对应的驱动,不要求安装cuda,[但pytorch要求安装cuda和cudnn(暂不确定)],如果本机的驱动版本小于cuda10.0对应的驱动版本,建议安装cuda10.x的驱动来覆盖本机的驱动,不用卸载再安装驱动下载cuda10.2…

    2022年9月23日
    3
  • 抽象类和接口(我学习做的笔记供大家参考)

    抽象类和接口(我学习做的笔记供大家参考)

    2021年5月24日
    97

发表回复

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

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