Nginx 踩坑日志

1.ngin.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.

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;

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;

}

2.Nginx 常用指令:

nginx 启动 nginx -t 检查配置文件   nginx -s reload  重启服务

3.Nginx 子站设置(SSH):

server {
listen 443;
server_name canmeng.net;
ssl on;
ssl_certificate /SSH/1_canmeng.net_bundle.crt;
ssl_certificate_key /SSH/2_canmeng.net.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;

#access_log logs/host.access.log main;
location / {
root /WEB/B;  #路径
#wp规则
try_files $uri $uri/ /index.php?$args;

#指引index
index default.php index.php index.html index.htm;
#站点的rewrite在这里写
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}
#错误页的配置
error_page 404 /error.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /WEB/B$fastcgi_script_name;   # File not found.PHP模块引导设置这里
include fastcgi_params;
}

}

4.Nginx子站设置:

server {
listen 80;
server_name canmeng.net;
#access_log logs/host.access.log main;
location / {
root /路径/BTZ;
index default.php index.php index.html index.htm;
#站点的rewrite全站跳HTTPS
#rewrite ^(.*) https://$host$1 permanent;
}
#错误页的配置
error_page 404 /error.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /WEB/B$fastcgi_script_name;
include fastcgi_params;
}

}

5.Nginx+PHP+mysql安装

yum install nginx -y

chkconfig nginx on  #开机启动

yum install mysql-server -y

service mysqld restart #启动mysql

/usr/bin/mysqladmin -u root password ‘MyPas$can4Wmeng_Press’  #密码

chkconfig mysqld on  #开机启动

yum install php-fpm php-mysql -y

service php-fpm start  #启动 PHP-FPM 进程

netstat -nlpt | grep php-fpm  #测试监听端口

chkconfig php-fpm on  #开机启动



1 thought on “Nginx 踩坑日志”

发表评论

电子邮件地址不会被公开。