本文为系列文章,该系列主要包含如何一步步在Linux上搭建项目。主要分为如何在
Linux下如何配置nginx等。
文章目录
一、在配置前首先确保正确安装nginx
具体步骤请看:Linux下安装nginx
二、配置nginx规则
1.建立文件目录层次
适用于域名的多项目配置,首先需要在 /usr/local/nginx/conf 中新建一个文件夹,存放相对的域名nginx配置的重写规则。
如果对Linux操作命令不太熟悉的小伙伴,可以下载Xhell+ftp,有免费的社区版,对于初学者很友好。
在 /usr/local/nginx/conf 中新建一个文件夹hosts,里面会放每一个项目的具体配置规则,而在nginx.conf中会放公共的配置规则
如下,hosts下放着项目的配置规则
2.更改nginx.conf中的规则
公共规则:
user www;
worker_processes auto;
error_log /data/logs/nginx/error/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
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 /data/logs/nginx/access/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
# 隐藏WEB语言框架
proxy_hide_header X-Powered-By;
# 隐藏NGINX版本号
server_tokens off;
# 请求体限制大小
client_max_body_size 1000m;
# 添加real_ip配置
set_real_ip_from 100.0.0.0/8; # 必须是 SLB 的内网 IP eg : 100.97.15.0/24
real_ip_header X-Forwarded-For;
# 多层加头,暂时不考虑
# real_ip_recursive on;
include hosts/*.conf;
}
3.在 /hosts 中再配置 项目的server规则
基于http访问的
- 后端项目
server {
listen 80;
# 你请求的网址
server_name www.****.com;
# 指向项目的启动路径
root /data/www/depu/server/public;
index index.php index