Nginx简单使用教程

369 字
2 分钟
Nginx简单使用教程

1、找到自己安装的nginx的配置文件所在#

这里配置路径示例为:/etc/nginx/sites-available/default

2、修改nginx配置文件#

Terminal window
vim /etc/nginx/sites-available/default

示例的内网接口为:

  • 127.0.0.1:8899/interface/demo1
  • 127.0.0.1:8899/interface/demo2
  • 127.0.0.1:8899/interface/demo3

(PS:外网域名映射到内网需自己查资料实现)

修改配置文件

Terminal window
server {
#公网映射监听的端口
listen 8088 default_server;
listen [::]:8088 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location /v1/user/register {
deny all;
return 403;
}
location /hidden_danger {
root /etc/nginx/html;
index index.html;
}
location ~ ^/(ai/gangjin/(demo1|demo2|demo3))$ {
add_header Cache-Control no-cache;
add_header Cache-Control private;
expires -1s;
proxy_cache off;
proxy_buffering off;
chunked_transfer_encoding on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 300;
proxy_pass http://127.0.0.1:8899;
}
location / {
add_header Cache-Control no-cache;
add_header Cache-Control private;
expires -1s;
proxy_cache off;
proxy_buffering off;
chunked_transfer_encoding on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 300;
proxy_pass http://127.0.0.1:8089; #映射到内网服务器的其它端口
}
}

3、修改配置后保存生效#

Terminal window
# 检查配置文件语法:在重载或重启 Nginx 之前,必须确保配置文件语法正确,避免因错误配置导致服务无法启动。使用以下命令检查:
sudo nginx -t
# 输出示例
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful
# 如果看到类似上述的成功提示,则表示配置语法正确,可以继续下一步。如果出现错误信息(如failed或err
# 平滑重启会在不中断现有连接的情况下加载新配置,适用于生产环境
sudo nginx -s reload
#或者
sudo systemctl reload nginx
# 检查服务状态
sudo systemctl status nginx

测试公网调用服务是否正常即可。

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

打赏
Nginx简单使用教程
https://firefly.cuteleaf.cn/posts/obsidian/nginx简单使用教程/
作者
Firefly
发布于
2026-06-29
许可协议
CC BY-NC-SA 4.0
相关文章 智能推荐
1
Nginx可视化
运维部署 Nginx 1、Nginx 可视化 可以一试 test 配置管理和性能监控 github地址: https://github.com/onlyGuo/nginx gui 1、下载和配置 首先到作者github说明页面,下载对应系统版本的安装包 需要注意的是linux版本有一段描述
2
Nginx详细用法介绍
运维部署 介绍链接: 1. https://blog.csdn.net/weixin 43239880/article/details/130841067 2. https://mp.weixin.qq.com/s/r7GFKbRhZFg0wKICbEJpXQ
3
Nginx在Linux下安装教程
运维部署 Nginx安装 1、首先安装包并解压 这里下载的是 nginx 1.17.10.tar.gz 安装包,并将其直接放在了 root 目录下 在 /usr/local/ 下创建 nginx 文件夹并进入 将 Nginx 安装包解压到 /usr/local/nginx 中即可 解压完之
4
Jenkins基础教程
运维部署 Jenkins Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件项目可以进行持续集成 官方网站 https://www.jenkins.io/ 使用前相关软件安装准备: GitLab安装使用 官
5
Docker部署MinIO分布式文件存储服务及其使用教程
运维部署 Docker部署MinIO分布式文件存储服务及其教程 1、什么是MinIO? Minio 是个基于 Golang 编写的开源对象存储套件,基于Apache License v2.0开源协议,虽然轻量,却拥有着不错的性能。它兼容亚马逊S3云存储服务接口。可以很简单的和其他应用结合使
随机文章 随机推荐
Profile Image of the Author
Firefly
Hello, I'm Firefly.
公告
欢迎来到我的博客!这是一则示例公告。
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
85
分类
5
标签
11
总字数
50,344
运行时长
0
最后活动
0 天前
站点信息
构建平台
Local
博客版本
Firefly v6.12.3
文章许可
CC BY-NC-SA 4.0

文章目录