码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Linux安装nginx教程


    目录

    一、Nginx下载

    二、安装步骤

    1、在 /docker目录下新建 nginx 文件夹

    2、将解压包移动到nginx目录下并解压到nginx目录

    3、进入 nginx目录,找到 configure

    4、运行 configure,命令 

    5、安装 

    6、查看根目录

    7、进入Nginx目录下的conf文件夹

    三、运行Nginx

    1、进入Nginx的根目录中的sbin目录

    2、按默认配置启动

    3、输入地址运行

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

    1、找到 /conf 目录下的 nginx.conf 配置文件

    2、直接使用finalshell打开nginx.conf

    ​3、修改监听端口为666

    4、重启nginx

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

    1、启动 spring boot 项目

    2、在浏览器中测试访问接口

    3、进行nginx配置

    4、运行结果测试

    5、结果测试


    一、Nginx下载

    从官网中下载 nginx 压缩包到本地(http://nginx.org/en/download.html)

    二、安装步骤

    1、在 /docker目录下新建 nginx 文件夹

    mkdir /docker/nginx

    2、将解压包移动到nginx目录下并解压到nginx目录

    tar -zxvf nginx-1.24.0.tar.gz

    3、进入 nginx目录,找到 configure

    yum -y install gcc openssl openssl-devel pcre-devel zlib zlib-devel

    4、运行 configure,命令 

    ./configure

    5、安装 

    make
    make install

    6、查看根目录

    whereis nginx 

    7、进入Nginx目录下的conf文件夹

    cd /usr/local/nginx/conf 

    里面又nginx.conf配置文件可以进行配置 

    三、运行Nginx

    1、进入Nginx的根目录中的sbin目录

    cd /usr/local/nginx/sbin

    2、按默认配置启动

    ./nginx 

    3、输入地址运行

    Welcome to nginx!

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

    1、找到 /conf 目录下的 nginx.conf 配置文件

    cd usr/local/nginx/nginx-1.24.1/conf/

    2、直接使用finalshell打开nginx.conf

    3、修改监听端口为666

    4、重启nginx

    ./nginx -s reload

     

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

    1、启动 spring boot 项目

    2、在浏览器中测试访问接口

    这是本地项目接口

    192.168.31.196:8888/course/test/01

    3、进行nginx配置

    1. #user nobody;
    2. worker_processes 1;
    3. #error_log logs/error.log;
    4. #error_log logs/error.log notice;
    5. #error_log logs/error.log info;
    6. #pid logs/nginx.pid;
    7. events {
    8. worker_connections 1024;
    9. }
    10. http {
    11. include mime.types;
    12. default_type application/octet-stream;
    13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    14. # '$status $body_bytes_sent "$http_referer" '
    15. # '"$http_user_agent" "$http_x_forwarded_for"';
    16. #access_log logs/access.log main;
    17. sendfile on;
    18. #tcp_nopush on;
    19. #keepalive_timeout 0;
    20. keepalive_timeout 65;
    21. #gzip on;
    22. server {
    23. listen 80;
    24. server_name localhost;
    25. #charset koi8-r;
    26. #access_log logs/host.access.log main;
    27. location / {
    28. root html;
    29. index index.html index.htm;
    30. }
    31. #error_page 404 /404.html;
    32. # redirect server error pages to the static page /50x.html
    33. #
    34. error_page 500 502 503 504 /50x.html;
    35. location = /50x.html {
    36. root html;
    37. }
    38. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    39. #
    40. #location ~ \.php$ {
    41. # proxy_pass http://127.0.0.1;
    42. #}
    43. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    44. #
    45. #location ~ \.php$ {
    46. # root html;
    47. # fastcgi_pass 127.0.0.1:9000;
    48. # fastcgi_index index.php;
    49. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    50. # include fastcgi_params;
    51. #}
    52. # deny access to .htaccess files, if Apache's document root
    53. # concurs with nginx's one
    54. #
    55. #location ~ /\.ht {
    56. # deny all;
    57. #}
    58. }
    59. # another virtual host using mix of IP-, name-, and port-based configuration
    60. #
    61. #server {
    62. # listen 8000;
    63. # listen somename:8080;
    64. # server_name somename alias another.alias;
    65. # location / {
    66. # root html;
    67. # index index.html index.htm;
    68. # }
    69. #}
    70. # HTTPS server
    71. #
    72. #server {
    73. # listen 443 ssl;
    74. # server_name localhost;
    75. # ssl_certificate cert.pem;
    76. # ssl_certificate_key cert.key;
    77. # ssl_session_cache shared:SSL:1m;
    78. # ssl_session_timeout 5m;
    79. # ssl_ciphers HIGH:!aNULL:!MD5;
    80. # ssl_prefer_server_ciphers on;
    81. # location / {
    82. # root html;
    83. # index index.html index.htm;
    84. # }
    85. #}
    86. server {
    87. listen 8888;
    88. server_name localhost;
    89. location /course/ {
    90. proxy_pass http://192.168.31.196:8888/course/;
    91. }
    92. }
    93. }

    最下方就是server的监听端口8888,通过/course跳转到windows的ip地址/course,并进行转发

    4、运行结果测试

    虚拟机ip地址:

    5、结果测试

    成功从192.168.58.131跳转到192.168.31.196

    并访问端口成功

  • 相关阅读:
    嵌入式Ubuntu根文件系统移植带桌面
    HTML + HTTP请求 +CSS知识点
    MDM数据清洗功能开发说明
    Stream + 并行流 +Optional +接口的方法 +日期组件+重复注解及类型注解
    机器人走迷宫问题
    帧间预测一些概念
    Springboot健康饮食小程序的设计的实现毕业设计源码280920
    怎么在火狐浏览器中添加IDM下载器扩展?
    《Jetpack Compose从入门到实战》 第二章 了解常用UI组件
    GBase8s数据库FOR READ ONLY 子句
  • 原文地址:https://blog.csdn.net/weixin_55127182/article/details/132744489
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号