nginx使用教程
配置文件
nginx -t
ps -ef | grep nginx
负载均衡
events {
worker_connections 1024;
}
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 重新打开日志文件