广告
返回顶部
首页 > 资讯 > 操作系统 >Linux 部署 Nginx
  • 948
分享到

Linux 部署 Nginx

nginxlinuxjava服务器 2023-09-21 06:09:31 948人浏览 泡泡鱼
摘要

文章目录 一、Nginx 下载二、部署步骤三、演示修改 Nginx 配置,修改端口号四、使用 Nginx 转发访问后端服务五、Nginx 常用命令 一、Nginx 下载 从官网中下载 n

文章目录


一、Nginx 下载

从官网中下载 nginx 压缩包到本地(Http://nginx.org/en/download.html
在这里插入图片描述

二、部署步骤

  1. 在 /usr/local 目录下新建 nginx 文件夹
[root@iZwz9cwntagbp2m20emj0qZ local]# mkdir nginx            [root@iZwz9cwntagbp2m20emj0qZ local]# ls                     aeGIS  app  bin  etc  games  include  lib  lib64  libexec  nginx  sbin  share  src
  1. 将 nginx 压缩包使用 SFTP 上传到 linux 系统的 /usr/local/nginx 目录下
[root@iZwz9cwntagbp2m20emj0qZ nginx]# ls                     nginx-1.22.1.tar.gz  
  1. 解压 nginx-1.22.1.tar.gz
[root@iZwz9cwntagbp2m20emj0qZ nginx]# tar -zxvf nginx-1.22.1.tar.gz                      nginx-1.22.1/                    nginx-1.22.1/auto/ ......[root@iZwz9cwntagbp2m20emj0qZ nginx]# ls                     nginx-1.22.1  nginx-1.22.1.tar.gz
  1. 进入 nginx,找到 configure
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/nginx-1.22.1/                [root@iZwz9cwntagbp2m20emj0qZ nginx-1.22.1]# ls       auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src 
  1. 运行 configure,命令 ./configure
[root@iZwz9cwntagbp2m20emj0qZ nginx-1.22.1]# ./configure

①如果报错执行yum -y install pcre-devel // 安装pore
②如果再次报错执行 yum -y install openssl openssl-devel //安装openssl

  1. 编译 nginx 文件
[root@iZwz9cwntagbp2m20emj0qZ nginx-1.22.1]# make[root@iZwz9cwntagbp2m20emj0qZ nginx-1.22.1]# make install
  1. 检查是否安装成功
[root@iZwz9cwntagbp2m20emj0qZ nginx-1.22.1]# whereis nginx                        nginx: /usr/local/nginx
  1. 找到 ngingx 的 sbin 目录
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/ [root@iZwz9cwntagbp2m20emj0qZ nginx]# ll              total 1092                drwx------ 2 nobody root    4096 Mar 14 11:39 client_body_temp                    drwxr-xr-x 2 root   root    4096 Mar 14 14:31 conf    drwx------ 2 nobody root    4096 Mar 14 11:39 fastcgi_temp                        drwxr-xr-x 2 root   root    4096 Mar 14 11:37 html    drwxr-xr-x 2 root   root    4096 Mar 14 14:37 logs    drwxr-xr-x 9   1001 1001    4096 Mar 14 11:33 nginx-1.22.1                        -rw-r--r-- 1 root   root 1073948 Mar 14 11:19 nginx-1.22.1.tar.gz                 drwx------ 2 nobody root    4096 Mar 14 11:39 proxy_temp                          drwxr-xr-x 2 root   root    4096 Mar 14 11:37 sbin    drwx------ 2 nobody root    4096 Mar 14 11:39 scgi_temp                           drwx------ 2 nobody root    4096 Mar 14 11:39 uwsgi_temp[root@iZwz9cwntagbp2m20emj0qZ nginx]# cd sbin/
  1. 启动 nginx
[root@iZwz9cwntagbp2m20emj0qZ sbin]# ./nginx
  1. 访问测试
    在这里插入图片描述

三、演示修改 Nginx 配置,修改端口号

  1. 找到 /conf 目录下的 nginx.conf 配置文件
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/nginx-1.22.1/conf/           [root@iZwz9cwntagbp2m20emj0qZ conf]# ll               total 40                  -rw-r--r-- 1 1001 1001 1077 Oct 19 16:02 fastcgi.conf -rw-r--r-- 1 1001 1001 1007 Oct 19 16:02 fastcgi_params                           -rw-r--r-- 1 1001 1001 2837 Oct 19 16:02 koi-utf      -rw-r--r-- 1 1001 1001 2223 Oct 19 16:02 koi-win      -rw-r--r-- 1 1001 1001 5349 Oct 19 16:02 mime.types   -rw-r--r-- 1 1001 1001 2656 Oct 19 16:02 nginx.conf   -rw-r--r-- 1 1001 1001  636 Oct 19 16:02 scgi_params  -rw-r--r-- 1 1001 1001  664 Oct 19 16:02 uwsgi_params -rw-r--r-- 1 1001 1001 3610 Oct 19 16:02 win-utf 
  1. 使用 vim 编辑 nginx.conf 文件
[root@iZwz9cwntagbp2m20emj0qZ conf]# vim nginx.conf

修改监听端口为666

server {                      listen       666;          server_name  localhost;}        

保存并退出:esc -> shift + : -> wq
3. 重新加载 nginx.conf 配置文件

[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/sbin/                        [root@iZwz9cwntagbp2m20emj0qZ sbin]# ll               total 3804                -rwxr-xr-x 1 root root 3892016 Mar 14 11:37 nginx     [root@iZwz9cwntagbp2m20emj0qZ sbin]# ./nginx -s reload
  1. 测试端口修改是否成功
    在这里插入图片描述

四、使用 Nginx 转发访问后端服务

  1. 启动 Spring Boot 项目
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/app/                [root@iZwz9cwntagbp2m20emj0qZ app]# ll total 16160-rw-r--r-- 1 root root 16546230 Mar 14 14:23 SpringBoot-0.0.1-SNAPSHOT.jar                     [root@iZwz9cwntagbp2m20emj0qZ app]# java -jar springboot-0.0.1-SNAPSHOT.jar     .   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \                           ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \                           \\/  ___)| |_)| | | | | || (_| |  ) ) ) )                           '  |____| .__|_| |_|_| |_\__, | / / / /                           =========|_|==============|___/=/_/_/_/:: Spring Boot ::        (v2.3.6.RELEASE)        2023-03-14 20:05:22.440  INFO 30885 --- [           main] c.JSON.springboot.SpringbootApplication  : Starting SpringbootApplication v0.0.1-SNAPSHOT on iZwz9cwntagbp2m20emj0qZ with PID 30885 (/usr/local/app/springboot-0.0.1-SNAPSHOT.jar started by root in /usr/local/app)    2023-03-14 20:05:22.454  INFO 30885 --- [           main] c.json.springboot.SpringbootApplication  : No active profile set, falling back to default profiles: default              2023-03-14 20:05:24.718  INFO 30885 --- [           main] o.s.b.w.embedded.Tomcat.TomcatWEBServer  : Tomcat initialized with port(s): 666 (http)       2023-03-14 20:05:24.747  INFO 30885 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]                         2023-03-14 20:05:24.748  INFO 30885 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.39]   2023-03-14 20:05:24.891  INFO 30885 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/json]   : Initializing Spring embedded WebApplicationContext2023-03-14 20:05:24.892  INFO 30885 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2320 ms               2023-03-14 20:05:25.793  INFO 30885 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'                        2023-03-14 20:05:26.188  INFO 30885 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 666 (http) with context path '/json'               2023-03-14 20:05:26.219  INFO 30885 --- [           main] c.json.springboot.SpringbootApplication  : Started SpringbootApplication in 4.683 seconds (JVM running for 5.522)        2023-03-14 20:06:06.170  INFO 30885 --- [-NIO-666-exec-4] o.a.c.c.C.[Tomcat].[localhost].[/json]   : Initializing Spring DispatcherServlet 'dispatcherServlet'                     2023-03-14 20:06:06.170  INFO 30885 --- [-nio-666-exec-4] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'          2023-03-14 20:06:06.187  INFO 30885 --- [-nio-666-exec-4] o.s.web.servlet.DispatcherServlet        : Completed initialization in 17 ms
  1. 在浏览器中测试访问接口
    在这里插入图片描述

  2. 在 nginx.conf 文件中配置 location

[root@iZwz9cwntagbp2m20emj0qZ ~]# cd / [root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/nginx-1.22.1/conf/                        [root@iZwz9cwntagbp2m20emj0qZ conf]# vim nginx.confserver {   listen       80;                   server_name  localhost;                 location /json/ {                      proxy_pass http://112.74.190.252:666/json/;                }}
  1. 重新加载 nginx.conf 配置文件
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/sbin/         [root@iZwz9cwntagbp2m20emj0qZ sbin]# lltotal 3804 -rwxr-xr-x 1 root root 3892016 Mar 14 11:37 nginx                  [root@iZwz9cwntagbp2m20emj0qZ sbin]# ./nginx -s reload
  1. 浏览器中测试(使用 Nginx 监听的 80 端口访问)
    在这里插入图片描述

五、Nginx 常用命令

  1. 查看 nginx 位置
[root@iZwz9cwntagbp2m20emj0qZ /]# whereis nginx       nginx: /usr/local/nginx
  1. 启动 nginx
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/sbin/                        [root@iZwz9cwntagbp2m20emj0qZ sbin]# ./nginx
  1. 停止 nginx
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/sbin/                        [root@iZwz9cwntagbp2m20emj0qZ sbin]# ./nginx -s stop
  1. 安全退出 nginx
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/sbin/                        [root@iZwz9cwntagbp2m20emj0qZ sbin]# ./nginx -s quit  
  1. 重新加载配置文件
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/sbin/                        [root@iZwz9cwntagbp2m20emj0qZ sbin]# ./nginx -s reload 

(注意:Nginx 启动、停止、退出、重新加载命令都需要在 sbin 目录下执行)

  1. 查看 nginx 进程
[root@iZwz9cwntagbp2m20emj0qZ /]# cd usr/local/nginx/sbin/                        [root@iZwz9cwntagbp2m20emj0qZ sbin]# ./nginx          [root@iZwz9cwntagbp2m20emj0qZ sbin]# ps aux|grep nginxroot     30537  0.0  0.0  20576   624 ?        Ss   16:41   0:00 nginx: master process ./nginx                nobody   30538  0.0  0.0  21020  1320 ?        S    16:41   0:00 nginx: worker process                        root     30542  0.0  0.0 112812   980 pts/0    S+   16:41   0:00 grep --color=auto nginx

来源地址:https://blog.csdn.net/WJH_JSON/article/details/129539291

--结束END--

本文标题: Linux 部署 Nginx

本文链接: https://www.lsjlt.com/news/413657.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Linux 部署 Nginx
    文章目录 一、Nginx 下载二、部署步骤三、演示修改 Nginx 配置,修改端口号四、使用 Nginx 转发访问后端服务五、Nginx 常用命令 一、Nginx 下载 从官网中下载 n...
    99+
    2023-09-21
    nginx linux java 服务器
  • Linux部署Nginx详解
    目录 前言 一、什么是Nginx?  二、什么是代理服务器? 三、什么是正向代理?  正向代理的用途: 四、什么是反向代理?  反向代理的作用: 五、什么是负载均衡? 但并发量大的时候如何解决? Nginx给出来三种关于负载均衡的方式: 六...
    99+
    2023-10-26
    linux nginx 服务器
  • Nginx Linux安装部署详细教程
    一、Nginx简介 Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡,具体简介我就不介绍了百度一下有很多,下面直接进入安装步骤 二、Nginx安装 1、下载Nginx及相关组件 ...
    99+
    2022-06-04
    Nginx Linux安装部署 Linux安装Nginx详细教程
  • nginx服务部署
     作者:Georgekai归档:学习笔记2018/2/2 nginx服务部署1.1 常用web软件了解1.1.1 web服务主流软件地址https://w3techs...
    99+
    2022-10-18
  • django+uwsgi+nginx部署
    django+uwsgi+nginx部署   1.介绍:   在网上看了很多教程,但自己部署了很久都没有成功,这篇博文记录自己所踩过得坑。   2.环境: 1 Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-13...
    99+
    2023-01-30
    django uwsgi nginx
  • docker-compose部署nginx+php
    1、首先拉取nginx及php镜像 docker pull nginx:1.21.6 docker pull php:7.4.28-fpm 2、创建本地目录 mkdir /home/nginx-php...
    99+
    2023-09-09
    php nginx docker
  • uwsgi+nginx项目部署
    部署Django项目 Django+uWSGI+nginx 部署 django 一个pyhton的开源web框架。 uWSGI 一个基于自有的uwsgi协议、WSGI协议和http服务协议的web网关 nginx 常用的代理服务器 ...
    99+
    2023-01-31
    项目 uwsgi nginx
  • nginx+uwsgi部署django项
    1、django项目部署前需要生成admin的静态资源文件 (1)生成admin的静态资源文件   # 关闭debug模型 DEBUG = False # 允许所有域名访问 ALLOWED_HOSTS = ['*'] # 静态资源路径 ...
    99+
    2023-01-31
    nginx uwsgi django
  • 在MacOS+Linux+Nginx中发布和部署Asp.Net Core
    目录新建一个 WebApp 项目发布到 Linux,Mac OS使用 Nginx 进行反向代理Mac OSLinux(Ubuntu)注意事项新建一个 WebApp 项目 在 Asp....
    99+
    2022-11-12
  • Docker上如何部署Nginx
    本篇内容主要讲解“Docker上如何部署Nginx”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Docker上如何部署Nginx”吧!1.从 docker 下载 Nginx 镜像docker&n...
    99+
    2023-06-30
  • Nginx热部署的实现
    目录信号量Nginx热部署跟着上面这篇博客进行操作即可。关闭防火墙,让本地可以通过浏览器访问Nginx服务。 [root@localhost ~]# systemctl stop...
    99+
    2022-11-12
  • Nginx集群部署方案
    工作需要,记录一下 一、Nginx安装 集群部署需要在主服务器安装Nginx服务,以下为安装步骤: 1.访问Nginx官网(http://nginx.org/en/download.html),下载Nginx安装包。 2.下载后解压至C盘...
    99+
    2023-09-08
    服务器 nginx 运维
  • Docker中怎么部署nginx
    这篇“Docker中怎么部署nginx”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Docker中怎么部署nginx”文章吧...
    99+
    2023-06-27
  • 如何部署Nginx服务
    本篇内容主要讲解“如何部署Nginx服务”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何部署Nginx服务”吧!1. Nginx介绍:1.1 Nginx是什么?Nginx(“engine x”...
    99+
    2023-06-29
  • HAproxy+keepalived+nginx实验部署
    目录 部署Haproxy+keepalived 一,配置主服务器(haproxy) 1,关闭防火墙   2,安装依赖环境   3,编译安装haproxy  4,haproxy服务配置文件修改  2.keepalived配置  二,备用服务...
    99+
    2023-09-01
    nginx 运维 服务器
  • Nginx静态资源部署
    目录 Nginx静态资源概述 Nginx静态资源的配置指令 listen指令  server_name指令 location指令  设置请求资源的目录root / alias index指令  error_page指令 静态资源优化配置语法...
    99+
    2023-08-31
    nginx 前端 服务器
  • 如何在MacOS+Linux+Nginx中发布和部署Asp.Net Core
    这篇文章主要介绍“如何在MacOS+Linux+Nginx中发布和部署Asp.Net Core”,在日常操作中,相信很多人在如何在MacOS+Linux+Nginx中发布和部署Asp.Net Core问题上存在疑惑,小编...
    99+
    2023-06-22
  • linux上nginx安装部署及使用过程详解
    1.下载 官网下载地址 2.部署 2.1安装前提 在linux下安装需要安装一下组件 1. gcc && g++ yum install gcc-c++ 2. pcre yum install -y pcre pc...
    99+
    2022-06-04
    linux nginx安装部署 linux上部署nginx linux nginx安装
  • Django+Nginx+uwsgi服务器部署
    一、安装 uwsgi uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议,旨在提供专业的 Python web应用发布和开发。Nginx中HttpUwsg...
    99+
    2022-11-13
  • Nginx如何部署SpringBoot项目
    本篇内容介绍了“Nginx如何部署SpringBoot项目”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!新建一个yml文件 applicat...
    99+
    2023-07-05
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作