首页 > 系统相关 >Nginx 系列2 --- 配置

Nginx 系列2 --- 配置

时间:2023-12-16 23:23:01浏览次数:27  
标签:系列 conf etc sudo --- Nginx html nginx http

一、概要

1. 承上启下

(1) Nginx 系列

二、配置

1. 测试配置

sudo nginx -t

2. nginx配置文件

(1) 配置文件

sudo vi /etc/nginx/nginx.conf

(2) 关键配置

events {
  worker_connections  4096;  ## Default: 1024
}
http {
  server {
    listen 80;
    listen [::]:80;
    server_name localhost;
    location / {
      root /etc/nginx/html;
      index index.html index.htm;
    }
  }
}

a. listen: 是nginx需要监听的端口号;

b. server_name: 是nginx代理的域名,如果配置成.example.com,则example.com所有子域名都会被命中;

c. location: 存储路径信息,这里root指http网站的根目录:

请求http://www.example.com/,返回页面对应的目录是/etc/nginx/html/index.html。

3. 子配置文件

(1) 按需创建

sudo vi /etc/nginx/conf.d/http
sudo vi /etc/nginx/conf.d/stream
sudo vi /etc/nginx/conf.d/mail
sudo vi /etc/nginx/conf.d/exchange-enhanced

a. Events: 一般链接处理;

b. Http: Http模块;

c. Mail: 邮件模块;

d. Stream: TCP和UDP流量。

(2) 在/etc/nginx/nginx.conf中按需添加引用

include /etc/nginx/conf.d/http/*.conf;
include /etc/nginx/conf.d/stream/*.conf;
include /etc/nginx/conf.d/exchange-enhanced/*.conf;

4. 防火墙

sudo firewall-cmd --permanent --add-service={http,https}
sudo firewall-cmd --reload

5. 配置服务

sudo systemctl start nginx
sudo systemctl enable nginx
systemctl status nginx

6. 配置证书

(1) Letscrypt证书

参考Letscrypt

(2) SELinux

使用自签发证书时,如果服务器开启了SELinux可能会出现Nginx无法加载证书文件的问题,此时需要运行以下命令解决:

sudo restorecon -v -R /etc/nginx/ssl

注意,/etc/nginx/ssl是证书所在的目录。

三、参考

1. 官方

http://nginx.org/en/docs/

http://nginx.org/en/docs/ngx_core_module.html

http://nginx.org/en/docs/http/ngx_http_core_module.html

http://nginx.org/en/docs/http/ngx_http_charset_module.html

http://nginx.org/en/docs/http/ngx_http_log_module.html

http://nginx.org/en/docs/mail/ngx_mail_ssl_module.html

http://nginx.org/en/docs/http/ngx_http_index_module.html

2. 其他

https://www.digitalocean.com/community/tools/nginx

标签:系列,conf,etc,sudo,---,Nginx,html,nginx,http
From: https://www.cnblogs.com/eagle6688/p/17665070.html

相关文章

  • 实验三-电子公文传输系统-个人贡献
    (一)简述你完成的工作我的工作主要是项目整体结构的搭建设计,和公文系统功能的实现一mvc模式和服务实现逻辑链设计在设计初期,我们确定好了分工和系统编写的基调。我认为电子公文系统中,可以采用MVC模式进行设计,得到了其他组员的支持,我们的分工也基本根据这个方式而来。其中我主要......
  • D - Erase Leaves
    D-EraseLeaveshttps://atcoder.jp/contests/abc333/tasks/abc333_d 思路把这个图看成一棵树,1作为树根,统计1树根关联的子节点作为根的子树的总节点数,去除子树中总节点数最大子的子树,其它子树的总节点记做贡献,最后+1(对应1节点)。 同时注意一个特殊情况,1仅有一......
  • 无涯教程-Java - boolean matches(String regex)函数
    此字符串是否与给定的正则表达式匹配,以str.matches(regex)形式调用此方法所产生的输出与表达式Pattern.matches(regex,str)完全相同。 booleanmatches-语法这是此方法的语法-publicbooleanmatches(Stringregex)这是参数的详细信息-regex  - 此字符串要匹配的正......
  • openGauss学习笔记-161 openGauss 数据库运维-备份与恢复-导出数据-使用gs_dump和gs_d
    openGauss学习笔记-161openGauss数据库运维-备份与恢复-导出数据-使用gs_dump和gs_dumpall命令导出数据-导出所有数据库-无权限角色导出数据161.1无权限角色导出数据gs_dump和gs_dumpall通过-U指定执行导出的用户帐户。如果当前使用的帐户不具备导出所要求的权限时,会无法导出......
  • File类的基础使用(四) - 删除功能
    1.4File类删除功能方法分类方法名说明publicbooleandelete()删除由此抽象路径名表示的文件或目录publicclassFileDemo03{publicstaticvoidmain(String[]args)throwsIOException{//Filef1=newFile("E:\\51cto\\java.txt");......
  • strcmp--memset
    strcmp用法--字符串库函数<string.h>memset函数用法头文件<string.h>strcmp#define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>#include<string.h>intmain(){ chararr1[]="xyd"; chararr2[]="***************"; strcpy(arr......
  • nginx启动、停止、重新加载
    原文:Windows下Nginx的启动、停止等命令_nginxwindows启动命令-CSDN博客启动:startnginx或nginx.exe      //前一个在后台运行,使用默认配置文件 nginx.exe-c配置文件       //指令配置文件 停止:nginx-sstop或nginx-squit //这好像停不......
  • C - Repunit Trio
    C-RepunitTriohttps://atcoder.jp/contests/abc333/tasks/abc333_c 思路N=333时候,repunit最长12位,三重遍历repunit做和记录到vector中最后对vector进行排序,取n值。 Codehttps://atcoder.jp/contests/abc333/submissions/48575689vector<longlong>sums;int......
  • 第八章:SpringBoot-Java工程及关系和修改启动logo(了解)
    一、springbootJava工程(了解)二、关闭&修改启动logo(了解)......
  • Q-learning与Sarsa算法辨析
     这个是Q-learing的一个算法,根据代码,它就是,先设定训练100次,然后,给它一个随机的状态,这里我们假设状态6就是终点,那么走迷宫的时候,如果没走到6,就要一直走下去,,所以里面还要用到一个while循环,然后在每个状态的时候,找一个非负的动作,存储在数组里,(算是合理动作的集合吧),下一个状态的指针......