nginx使用教程

nginx使用教程

配置文件

# 错误日志 /var/log/nginx/error.log 
# 访问日志 /var/log/nginx/access.log
# 验证nginx配置文件格式和配置是否存在异常,通过该命令会输出nginx的配置文件的路径和验证结果,在输出结果中就可以找到当前的nginx的加载的配置文件的地址
nginx -t
# 如果在nginx启动的过程中显式的配置了nginx配置文件的加载路径,通过这样的方式就可以很简单的看到当前的配置文件加载路径
ps -ef | grep nginx
# 通过 locate 命令来进行查找

负载均衡

# 全局配置
events {
    worker_connections   1024; # 连接数
}

http {
  # http 配置
  
  upstream xx {
      # 负载均衡配置
      # 服务器资源
      server 127.0.0.1:8000 weight=1
      server 127.0.0.1:8081 weight=1
  }
  server {
     listen    80;
     server_name   localhost;
     # 代理
     
     location / {
       root html;
       index  index.html index.htm;
       proxy_pass http://xx
     }
  }
    server {
     listen    443;
     server_name   localhost;
     # 代理
  }
}

nginx 配置php解析

1. 首先在nginx配置文件打开如下几行的注释:

location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }
        
只需要把SCRIPT_FILENAME的文件位置更改为如上所示即可

2. 然后检测nginx的配置文件是否正确,注意每一次更改配置文件后,都要进行此项检测!

[root@lnmp html]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


server {
    listen 80;
    listen 443 ssl http2;
    server_name .homestead.test;
    root "/home/vagrant/code/Laravel/public"; 这个选项一定要设置在public下面
    error_log  /var/log/nginx/homestead.test-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
        denay all;
    }

    ssl_certificate     /etc/nginx/ssl/homestead.test.crt;
    ssl_certificate_key /etc/nginx/ssl/homestead.test.key;
}

命令大全

配置语法检查:nginx -c ./conf/jason.conf -t
nginx -s reload 重新加载配置文件
nginx -s reopen 重新打开日志文件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值