Nginx配置及使用个人总结

Nginx配置及使用个人总结


1. 前言

根据使用场景,可能会将前后端分离(一些小的工具式web分离反而麻烦,直接打成一个程序包更好),这时Linux相关设备一般都会选择nginx进行配置处理,这里做下简单的总结。

2. 个人使用简单模板文件

worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile on;
    keepalive_timeout 0;

    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 1G;
    large_client_header_buffers 2 1k;

    gzip on;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 1;
    gzip_proxied any;

    #root /www;

    #server {
    #    listen 80 default_server;
    #    listen [::]:80 default_server;
    #    server_name _;
    #    return 301 https://$host$request_uri;
    #}

    #server {
    #    listen 443 ssl default_server;
    #    listen [::]:443 ssl default_server;
    #    server_name  localhost;

    #    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    #    ssl_prefer_server_ciphers on;
    #    ssl_ciphers #"EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:DHE+AESGCM:DHE:!RSA!aNULL:!eNULL:!LOW:!RC4:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!CAMELLIA:!SEED";
    #   ssl_session_tickets off;

    #    ssl_certificate /etc/nginx/nginx.cer;
    #    ssl_certificate_key /etc/nginx/nginx.key;

    #    location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
            expires 365d;
    #    }

    #    include luci_uwsgi.conf;

    #}


        server {
                listen  80;
                server_name 127.0.0.1;

                access_log   /var/log/gf-app-access.log;
                error_log    /var/log/gf-app-error.log;

                location ^~ / {
                        access_log off;
                        expires    1d;
                        root       /www/gateway_manage;
                        index  index.html index.htm;
                }
                location ^~ /gateway {
                        try_files  $uri @backend;
                        rewrite "^/(.*)$" /$1 break;
                }

                location @backend {
                        proxy_pass                 http://127.0.0.1:8081;
                        proxy_redirect             off;
                        proxy_set_header           Host             $host;
                        proxy_set_header           X-Real-IP        $remote_addr;
                        proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
                }
        }

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

3. 常用nginx命令

$nginx -h
nginx version: nginx/1.16.1 (x86_64-pc-linux-gnu)
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file

服务器重启之后,执行 nginx -t 是OK的,然而在执行 nginx -s reload 的时候报错

nginx: [error] invalid PID number "" in "/run/nginx.pid"

解决方法:

需要先执行

nginx -c /etc/nginx/nginx.conf

nginx.conf文件的路径可以从nginx -t的返回中找到。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昵称系统有问题

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值