nginx安装配置

news/发布时间2024/5/14 18:43:58

一、目录

1 linux 下安装nginx
2. nginx 配置
3. nginx 常用命令
4. 安装报错

二、实现

1 linux 下安装nginx
1. 安装 openssl 、zlib 、 gcc 、pcre依赖

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel
  1. 安装 nginx
    a 官网下载nginx:http://nginx.org
//创建一个文件夹
cd /usr/soft
//创建一个目录作为nginx的安装目录
mkdir nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz

b 使用命令解压,进入安装目录 >>cd nginx-1.13.7
指定路径>> ./configure

 //指定nginx安装的目录
./configure --prefix=/usr/soft/nginx

c 执行指令: make && make install
安装成功之后会自动生成/usr/local/nginx文件夹(文件中包括nginx 命令、配置、日志、资源)

  1. 启动测试
    ./usr/local/nginx/sbin/nginx
    访问服务器ip:80

在这里插入图片描述

# nginx默认监听端口是80,记得设置防火墙开放端口,或者直接关闭防火墙。
# 查看开放的端口
firewall-cmd --list-all
# 设置开放的端口
firewall-cmd --add-service=http --permanent
firewall-cmd --add-port=80/tcp --permanent
# 重启防火墙
firewall-cmd --reload

2. nginx 配置
1 nginx 做转发配置

实现效果:
使用nginx做反向代理,根据访问的路径跳转不通的服务。
nginx的监听端口为9001
访问http://127.0.0.1:9001/edu/ 跳转127.0.0.1:8080
访问http://127.0.0.1:9001/vod/ 跳转127.0.0.1:8081

找到nginx.conf进行配置

server{listen   9001;server_name localhost;location ~/edu/{proxy_pass http://127.0.0.1:8080/;    }location ~/vod/ {proxy_pass http://127.0.0.1:8081/; }
}

注:localhost后面的相当于一个正则校验,之后匹配的才会跳转到对应的代理。 需要在8080、8081 后加/

nginx.conf 具体实现:

#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;#   server {# listen       8011;# server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;# location / {#   root   html;#    index  index.html index.htm;# }#error_page  404              /404.html;# redirect server error pages to the static page /50x.html## error_page   500 502 503 504  /50x.html;#location = /50x.html {#   root   html;# }# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}#  }# another virtual host using mix of IP-, name-, and port-based configuration#server {listen       8091;#listen       somename:8011;server_name  localhost;location /edu {proxy_pass http://10.120.130.49:8021/;}}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

在这里插入图片描述
重启nginx.
在这里插入图片描述
配置解释:

配置解释
location [ = | ~ | ~* | ^~ ] uri {        
}= :用于不含正则表达式的uri前,需要请求字符串与uri严格匹配,如果匹配成功,停止继续向下搜索并立即处理该请求。
~ :用于表示uri包含正则表达式,并且区分大小写
~* :用于表示uri包含正则表达式,并且不区分大小写
^~ :用于不含正则表达式的 uri 前,要求 Nginx 服务器找到标识 uri 和请求字符串匹配度最高的 location 后,立即使用此 location 处理请求,而不再使用 location 块中的正则 uri 和请求字符串做匹配。
注意:如果 uri 包含正则表达式,则必须要有 ~ 或者 ~* 标识。
  1. 负载均衡 配置
    实现效果:浏览器地址栏输入:http://ip:9001/edu/a.html,负载均衡效果,平均到8080和8081端口。
    找到nginx.conf进行配置
    在这里插入图片描述
    重启nginx 服务。
nginx 配置
[root@dockermain nginx]# cat conf/nginx.conf#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;#   server {# listen       8011;# server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;# location / {#   root   html;#    index  index.html index.htm;# }#error_page  404              /404.html;# redirect server error pages to the static page /50x.html## error_page   500 502 503 504  /50x.html;#location = /50x.html {#   root   html;# }# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}#  }# another virtual host using mix of IP-, name-, and port-based configuration#upstream myserver {server 10.120.130.49:8021;            #意图服务1server 10.120.130.49:8020;#意图服务2}server {listen       8091;#listen       somename:8011;server_name  localhost;location /edu {proxy_pass http://myserver/;root html;}}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

在这里插入图片描述
3. nginx 常用命令

使用nginx操作命令的前提条件,必须进入nginx的目录cd /usr/local/nginx/sbin/
查看nginx版本号./nginx -v
启动nginx./nginx
关闭nginx./nginx -s stop
重新加载nginx./nginx -s reload修改端口:vim /conf/nginx.conf   中的80 端口   然后重启    

4. 安装报错

 src/http/ngx_http_script.c:698:18: error: cast between incompatible function types from ‘size_t (*)(ngx_http_script_engine_t *)’ {aka ‘long unsigned int (*)(struct <anonymous> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {aka ‘void (*)(struct <anonymous> *)’} [-Werror=cast-function-type]698 |     code->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;|                  ^
src/http/ngx_http_script.c: In function ‘ngx_http_script_add_var_code’:
src/http/ngx_http_script.c:787:18: error: cast between incompatible function types from ‘size_t (*)(ngx_http_script_engine_t *)’ {aka ‘long unsigned int (*)(struct <anonymous> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {aka ‘void (*)(struct <anonymous> *)’} [-Werror=cast-function-type]787 |     code->code = (ngx_http_script_code_pt) ngx_http_script_copy_var_len_code;
解决:
解决:进入Makefile
vim /usr/local/nginx-1.14.0/objs/Makefile
在文件中找到:CFLAGS =-pipe -0 -w -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
把 -Werror 删掉,然后保存退出后,重新make
src/os/unix/ngx_user.c:26:7: error: ‘struct crypt_data’ has no member named ‘current_salt’26 |     cd.current_salt[0] = ~salt[0];|       ^解决:vim src/os/unix/ngx_user.c注释掉cd.current_salt[0] = ~salt[0]/*cd.current_salt[0] = ~salt[0] */

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.bcls.cn/qSKx/3014.shtml

如若内容造成侵权/违法违规/事实不符,请联系编程老四网进行投诉反馈email:xxxxxxxx@qq.com,一经查实,立即删除!

相关文章

基于springboot财务管理系统源码和论文

随着信息技术和网络技术的飞速发展&#xff0c;人类已进入全新信息化时代&#xff0c;传统管理技术已无法高效&#xff0c;便捷地管理信息。为了迎合时代需求&#xff0c;优化管理效率&#xff0c;各种各样的管理系统应运而生&#xff0c;各行各业相继进入信息管理时代&#xf…

STM32面试相关问题

总结以下之前面试时遇到的一些问题&#xff0c;以便回顾起来学习&#xff01; 技术面试一般都是看项目提问的&#xff0c;可能会问&#xff1a; STM32的内核型号有哪些&#xff1f; 回答&#xff1a;ARM Cortex-M0&#xff0c;M0&#xff0c;M3, M4和M7内核&#xff0…

Java Swing游戏开发学习2

跟随大佬教程继续&#xff0c;图片资源&#xff0c;视频简介有下载链接。 这个文章是看视频教程写的&#xff0c;不算原创。有条件的可以去油管搜索RyiSnow&#xff0c;是一个游戏开发视频制作up主&#xff0c;讲解的非常基础&#xff0c;可以边看边实践&#xff0c;增加对Java…

利用Socket.io实现实时通讯功能

在当今快节奏的社交和工作环境中&#xff0c;实时通讯已经变得至关重要。无论是在线游戏的即时交流&#xff0c;还是团队协作中的实时消息传递&#xff0c;都需要强大的实时通讯功能来支持。而在前端开发中&#xff0c;利用Socket.io这一强大的工具库&#xff0c;实现实时通讯功…

统计图雷达图绘制方法

统计图雷达图绘制方法 常用的统计图有条形图、柱形图、折线图、曲线图、饼图、环形图、扇形图。 前几类图比较容易绘制&#xff0c;饼图环形图绘制较难。 还有一种雷达图的绘制也较难&#xff0c;今提供雷达图的绘制方法供参考。 本方法采用C语言的最基本功能&#xff1a; &am…

文件上传漏洞--Upload-labs--Pass09(在某些版本的靶场里是Pass10)--点+空格+点 绕过

一、什么是 点空格点 绕过 顾名思义&#xff0c;将 test.php 改为 test.php. . &#xff0c;观察到后缀名php后多出了 点空格点。那么 点空格点 是如何进行绕过的&#xff0c;在什么情况下可以使用&#xff0c;让我们结合题目讲解。 二、代码审计 1、查看题目源代码上半部分&…

MySQL

1 数据库简介 1.1 简介 数据库&#xff08;DataBase&#xff0c;DB&#xff09;&#xff1a;指长期保存在计算机的存储设备上&#xff0c;按照一定规则组织起来&#xff0c;可以被各种用户或应用共享的数据集合。 数据库管理系统&#xff08;DataBase Management System&…

Mysql数据库主从集群从库Slave因为RelayLog过多过大引起服务器硬盘爆满生产事故实战解决

Mysql数据库主从集群从库slave因为RelayLog过多过大引起从库服务器硬盘爆满生产事故实战解决 一、MySQL数据库主从集群概念 MySQL数据库主从集群是一种高可用性和读写分离的数据库架构&#xff0c;它基于MySQL的复制&#xff08;Replication&#xff09;技术来同步数据。在主…

三防平板丨平板终端丨加固平板丨户外勘测应用

随着科技的不断发展&#xff0c;现代勘测业也在不断升级。相较于传统的勘测设备&#xff0c;三防平板在户外勘测中有着广泛的应用。那么&#xff0c;三防平板在户外勘测中究竟有哪些优势呢&#xff1f; 首先&#xff0c;三防平板具备极强的防水、防尘、防摔能力。在野外勘测中&…

【JVM】打破双亲委派机制

&#x1f4dd;个人主页&#xff1a;五敷有你 &#x1f525;系列专栏&#xff1a;JVM ⛺️稳中求进&#xff0c;晒太阳 打破双亲委派机制 打破双亲委派机制三种方法 自定义类加载器 ClassLoader包含了四个核心方法 //由类加载器子类实现&#xff0c;获取二进制数据调用…

MyBatis框架-缓存

MyBatis缓存 简介 什么是缓存 [ Cache ]&#xff1f; 存在内存中的临时数据。将用户经常查询的数据放在缓存&#xff08;内存&#xff09;中&#xff0c;用户去查询数据就不用从磁盘上(关系型数据库数据文件)查询&#xff0c;从缓存中查询&#xff0c;从而提高查询效率&#…

超市售货|超市售货管理小程序|基于微信小程序的超市售货管理系统设计与实现(源码+数据库+文档)

超市售货管理小程序目录 目录 基于微信小程序的超市售货管理系统设计与实现 一、前言 二、系统功能设计 三、系统实现 1、微信小程序前台 2、管理员后台 &#xff08;1&#xff09;商品管理 &#xff08;2&#xff09;出入库管理 &#xff08;3&#xff09;公告管理 …

使用向量数据库pinecone构建应用04:混合搜索 Hybrid Search

Building Applications with Vector Databases 下面是这门课的学习笔记&#xff1a;https://www.deeplearning.ai/short-courses/building-applications-vector-databases/ Learn to create six exciting applications of vector databases and implement them using Pinecon…

dell戴尔电脑灵越系列Inspiron 15 3520原厂Win11系统中文版/英文版

Dell戴尔笔记本灵越3520原装出厂Windows11系统包&#xff0c;恢复出厂开箱预装OEM系统 链接&#xff1a;https://pan.baidu.com/s/1mMOAnvXz5NCDO_KImHR5gQ?pwd3nvw 提取码&#xff1a;3nvw 原厂系统自带所有驱动、出厂主题壁纸、系统属性联机支持标志、Office办公软件、MyD…

VSCode The preLaunchTask ‘C/C++: clang++ 生成活动文件‘ terminated with exit code -1

更改tasks.json文件里面的type为shell 选择g 选择g&#xff0c;然后点回到text.c&#xff0c;按下F5. 得到结果。 文中内容参考: 从零开始手把手教你配置属于你的VS Code_哔哩哔哩_bilibili https://blog.csdn.net/qq_63872647/article/details/128006861

制作商品说明书:如何突出产品特点和优势?

在当今高度竞争的市场环境下&#xff0c;一个优秀的商品说明书不仅是传递产品信息的桥梁&#xff0c;更是凸显产品特点和优势、吸引消费者注意力的关键。那么&#xff0c;如何在商品说明书中有效地突出产品的特点和优势呢&#xff1f;LookLook同学将从以下几个方面进行探讨。 |…

js设计模式:外观模式

作用: 将复杂的功能封装成可以简单调用的方法,无需知道内部的具体逻辑,只需要知道怎么去使用 类似于一把枪,你可以不知道内部的枪机,击发机,复进簧,枪管,导气装置,弹夹是怎么合作配合完成发射和自动填弹,你只需要知道你扣动扳机就能完成这一系列复杂的操作,而那个扳机就是外观…

【C++初阶】系统实现日期类

目录 一.运算符重载实现各个接口 1.小于 (d1)<> 2.等于 (d1d2) 3.小于等于&#xff08;d1<d2&#xff09; 4.大于&#xff08;d1>d2&#xff09; 5.大于等于&#xff08;d1>d2&#xff09; 6.不等于&#xff08;d1!d2&#xff09; 7.日期天数 (1) 算…

【机器学习的主要任务和应用领域】

曾梦想执剑走天涯&#xff0c;我是程序猿【AK】 目录 简述概要知识图谱 简述概要 了解机器学习的主要任务和应用领域 知识图谱 机器学习的主要任务可以分为监督学习、无监督学习和半监督学习。 监督学习&#xff1a;这是机器学习中最为常见的一类任务&#xff0c;基于已知类…

数据安全治理实践路线(上)

基于以上数据安全治理实践理念&#xff0c;可以按照自顶向下和自底向上相结合的思路推进实践过程。一方面&#xff0c;组织自顶向下,以数据安全战略规划为指导,以规划、建设、运营、优化为主线&#xff0c;围绕构建数据安全治理体系这一核心&#xff0c;从组织架构、制度流程、…
推荐文章