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


相关推荐

  • ubuntu系统下mysql重置密码和修改密码操作

    ubuntu系统下mysql重置密码和修改密码操作一、忘记密码后想重置密码在介绍修改密码之前,先介绍一个文件/etc/mysql/debian.cnf.其主要内容如下图:里面有一个debian-sys-maint用户,这个用户只有Debian或Ubuntu服务器才有,所以如果您的服务器是Debain或Ubuntu,debian-sys-maint是个Mysql安装之后自带的用户,具体作用是重启及运行mysql服务。所以如果忘了root密码,可以通…

    2022年5月31日
    49
  • Java创建WebService服务及客户端实现

    Java创建WebService服务及客户端实现简介WebService是一种服务的提供方式,通过WebService,不同应用间相互间调用变的很方便,网络上有很多常用的WebService服务,如:http://developer.51cto.com/art/200908/147125.htm,不同的语言平台对WebService都有实现,Java的WebService实现,比较流行的有Axis2、Jaxws,…

    2022年7月13日
    22
  • centos8安装rabbitmq_rabbitmq镜像集群

    centos8安装rabbitmq_rabbitmq镜像集群rabbitmq集群搭建1分别在3台节点安装rabbitmq-server在3台虚拟机(10.0.11.5410.0.11.5610.0.11.57)分别安装相同版本的rabbitmq-server及erlang,2分别修改三台节点的/etc/hosts文件注意必须修改主机名hostnamectlset-hostnamenode1#node2,3以此类推每台节点hosts文件修改后如下3将三台节点的.erlang.cookie内容修改一致(不一致创建集群会报错

    2025年10月24日
    4
  • kindeditor<=4.1.5上传漏洞复现

    kindeditor<=4.1.5上传漏洞复现0x00漏洞描述漏洞存在于kindeditor编辑器里,你能上传.txt和.html文件,支持php/asp/jsp/asp.net,漏洞存在于小于等于kindeditor4.1.5编辑器中这里

    2022年7月4日
    25
  • docker-jenkins安装node

    docker-jenkins安装node容器直接使用脚本安装报错执行如下命令即可解决gitconfig–global–unsethttp.proxygitconfig–global–unsethttps.proxy后续安装参考https://blog.csdn.net/qq_28686911/article/details/113114894

    2022年5月24日
    93
  • ELK日志系统7.10.0

    ELK日志系统7.10.0ELK 日志系统 Elasticsearc 部署 1 配置 JDK ES 运行依赖 JDK 7 x 版本需要 JDK11 版本 tar zxfjdk 11 0 9 linux x64 bin tar gz C usr local echo exportJAVA HOME usr local jdk 11 0 9exportPATH JAVA HOME bin PATH gt gt etc profilesourc etc profilejava version j

    2025年12月4日
    8

发表回复

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

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