Nginx配置使用详解


Posted in Servers onJuly 07, 2022

Nginx配置使用详解

配置步骤:

1、配置nginx的方法:首先要打开“/etc/nginx/conf.d/”文件夹;

2、然后创建配置文件;接着在“/etc/nginx/nginx.conf”文件中修改配置项;

3、最后重新启动nginx即可

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器
Nginx (engine x) 也是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的 

前后端nginx配置

1.打开 /etc/nginx/conf.d/文件夹,创建配置文件xxx.conf,内容如下:

server {
    listen 80;
    server_name **.106.2**.175;
    location / {
            root   /public/app/dist;
            index  index.php index.html index.htm;
    }

    location /sell {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   Host      $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass         http://127.0.0.1:8080;
        proxy_redirect off;

    }}

2.在 /etc/nginx/nginx.conf文件中有一行就是把刚刚配置的引进总的nginx配置中

...

    include /etc/nginx/conf.d/*.conf;...

3.配置完成后重新启动nginx

nginx -t                         # 查看nginx状态
nginx -s reload            # 重新载入配置文件
nginx -s reopen           # 重启 Nginx
nginx -s stop               # 停止 Nginx

4.配置https

server {
        listen 443;
        server_name xx.name.com;
        ssl on;
        index index.html index.htm;
        ssl_certificate   cert/215079423330181.cert;
        ssl_certificate_key  cert/215079423330181.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        location / {
           root   /public/app/dist;
           index  index.php index.html index.htm;
        }

        location /sell {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   Host      $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass         http://127.0.0.1:8080;
            proxy_redirect off;
        }
   }

5.nginx.conf 默认文件

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;


# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    gzip on;
    gzip_static on;
    gzip_min_length 1024;
    gzip_buffers 4 16k;
    gzip_comp_level 2;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript   application/x-httpd-php application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";


    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;


    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
         listen 443;
         server_name mp.hanxing.store;
         ssl on;
         index index.html index.htm;
         ssl_certificate   cert/cert_mp.hanxing.store.crt;
         ssl_certificate_key  cert/cert_mp.hanxing.store.key;
         ssl_session_timeout 5m;
         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
         ssl_prefer_server_ciphers on;

         location / {
            root   /public/sell/app/dist;
            index  index.php index.html index.htm;
         }

         location /sell {
             proxy_set_header   X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header   Host      $http_host;
             proxy_set_header X-NginX-Proxy true;
             proxy_pass         http://127.0.0.1:8080;
             proxy_redirect off;
         }

         error_page 404 /404.html;
              location = /40x.html {
         }

         error_page 500 502 503 504 /50x.html;
            location = /50x.html {
         }
    }
}

以上就是nginx怎么配置的详细内容!

到此这篇关于Nginx配置使用的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。


Tags in this post...

Servers 相关文章推荐
nginx基于域名,端口,不同IP的虚拟主机设置的实现
Mar 31 Servers
Nginx的反向代理实例详解
Mar 31 Servers
详解Apache SkyWalking 告警配置指南
Apr 22 Servers
苹果M1芯片安装nginx 并且部署vue项目步骤详解
Nov 20 Servers
关于Nginx中虚拟主机的一些冷门知识小结
Mar 03 Servers
Tomcat配置访问日志和线程数
May 06 Servers
netty 实现tomcat的示例代码
Jun 05 Servers
CentOS7环境下MySQL8常用命令小结
Jun 10 Servers
V Rising 服务器搭建图文教程
Jun 16 Servers
shell进度条追踪指令执行时间的场景分析
Jun 16 Servers
Ubuntu安装Mysql+启用远程连接的完整过程
Jun 21 Servers
Nginx如何限制IP访问只允许特定域名访问
Jul 23 Servers
nginx代理实现静态资源访问的示例代码
Jul 07 #Servers
使用 DataAnt 监控 Apache APISIX的原理解析
设置IIS Express并发数
Linux中sftp常用命令整理
Jun 28 #Servers
TaiShan 200服务器安装Ubuntu 18.04的图文教程
Jun 28 #Servers
Linux中各个目录的作用与内容
Windows Server 2008配置防火墙策略详解
You might like
php下保存远程图片到本地的办法
2010/08/08 PHP
PHP文件读写操作之文件读取方法详解
2011/01/13 PHP
带你了解PHP7 性能翻倍的关键
2015/11/19 PHP
Zend Framework教程之Zend_Layout布局助手详解
2016/03/04 PHP
详解PHP用substr函数截取字符串中的某部分
2016/12/03 PHP
javascript div 遮罩层封锁整个页面
2009/07/10 Javascript
jQuery 操作option的实现代码
2011/03/03 Javascript
利用js实现在浏览器状态栏显示访问者在本页停留的时间
2013/12/29 Javascript
深入理解$.each和$(selector).each
2016/05/15 Javascript
关于JavaScript和jQuery的类型判断详解
2016/10/08 Javascript
jquery checkbox的相关操作总结
2016/10/17 Javascript
vue脚手架vue-cli的学习使用教程
2017/06/06 Javascript
webpack打包后直接访问页面图片路径错误的解决方法
2017/06/17 Javascript
使用angular帮你实现拖拽的示例
2017/07/05 Javascript
详述 Sublime Text 打开 GBK 格式中文乱码的解决方法
2017/10/26 Javascript
jQuery实现下拉菜单动态添加数据点击滑出收起其他功能
2018/06/14 jQuery
微信小程序自定义扫码功能界面的实现代码
2020/07/02 Javascript
[49:18]2018DOTA2亚洲邀请赛 3.31 小组赛 A组 OG vs TNC
2018/04/01 DOTA
Python continue语句用法实例
2014/03/11 Python
Python实现以时间换空间的缓存替换算法
2016/02/19 Python
numpy中的高维数组转置实例
2018/04/17 Python
python处理csv中的空值方法
2018/06/22 Python
下载官网python并安装的步骤详解
2019/10/12 Python
Tensorflow进行多维矩阵的拆分与拼接实例
2020/02/07 Python
Python函数基本使用原理详解
2020/03/19 Python
简单了解Python变量作用域正确使用方法
2020/06/12 Python
CSS3结构性伪类选择器九种写法
2012/04/18 HTML / CSS
长青弘远的面试题
2012/06/09 面试题
大学四年规划书范文
2013/12/27 职场文书
法律专业应届生自荐信范文
2014/01/06 职场文书
关于祖国的演讲稿
2014/05/04 职场文书
精彩的演讲稿开头
2014/05/08 职场文书
2014年检察院个人工作总结
2014/12/09 职场文书
公司聚餐通知
2015/04/22 职场文书
python基础之爬虫入门
2021/05/10 Python
win10壁纸在哪个文件夹 win10桌面背景图片文件位置分享
2022/08/05 数码科技