阿里云nginx服务器多站点的配置
今天配置了一下多站点,记录一下配置的过程…
1、首先要找到nginx 配置文件之所在,阿里云上的nginx.conf 文件上 /alidata/server/nginx-1.4.4/conf 中。
2、然后在conf目录下创建一个vhosts 目录, 这个目录是用来存放不同站点的配置文件的。
3、然后呢, 在nginx.conf 最后 加入一行 include /alidata/server/nginx/conf/vhosts/*.conf;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 |
user www www;
worker_processes 1;
error_log /alidata/log/nginx/error .log crit;
pid /alidata/server/nginx/logs/nginx .pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application /octet-stream ;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text /plain application /x-javascript text /css application /xml ;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
log_format '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"' ;
# 加入下面一行 表示将 vhosts 下面所有的 conf 文件包含进来
include /alidata/server/nginx/conf/vhosts/ *.conf;
} |
4、然后,就是在vhosts 目录下写 你对应站点的 conf 文件了。下面给出一个范例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 |
server {
listen 80;
# 这个表示 网站域名, 可以是二级甚至多级域名
server_name localhost demo.com www.demo.com test .demo.com;
# 表示默认索引文件
index index.html index.htm index.php;
# 该站点对应的网站根目录所在
root /alidata/www/demo ;
location ~ .*\\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\\.(js|css)?$
{
expires 1h;
}
# 伪静态规则
include /alidata/server/nginx/conf/rewrite/phpwind .conf;
access_log /alidata/log/nginx/access/phpwind .log;
} |
5、如果还要继续添加, 直接复制文件。然后修改一下 server_name, root, 和access_log(如果有必要的话) 就OK了。
6、然后,不要立马重启nginx,应该要先测试一下nginx 配置文件是否正常. 找到nginx 的 sbin目录。 注意, 这个地方是nginx 的sbin 目录(这个目录与nginx 的conf 目录是同级目录)。linux 下有许多与sbin同名的目录。 容易搞错。 在阿里云服务器上一般默认的目录是 /alidata/server/nginx-1.4.4/sbin。
7、输入 cd /alidata/server/nginx-1.4.4/sbin,然后输入 ./nginx -t ,如果控制台显示下面两行,则表示配置成功了,否则请根据提示继续检查配置文件。
nginx: the configuration file /alidata/server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /alidata/server/nginx/conf/nginx.conf test is successful
8、配置成功之后, 就 需要重启 nginx 服务器。 在sbin目录下输入命令:./nginx -s reload, 然后整个过程就完成了。
另外, 总结一下nginx 的几个常用命令:
启动
1 |
./nginx |
重启
1 |
. /nginx -s reload |
关闭
1 |
ps -ef | grep nginx # 查询nginx主进程号 |
从容停止 kill -QUIT 主进程号
快速停止 kill -TERM 主进程号
强制停止 kill -9 nginx
若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
kill -信号类型 '/usr/local/nginx/logs/nginx.pid'
判断配置文件是否正确
1 |
. /nginx -t |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
原文链接:http://blog.csdn.net/acmore_xiong/article/details/52170276
相关文章
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
-
Linux中openssl/opensslv.h找不到问题的解决方法
2025-05-27 97 -
2025-05-25 76
-
2025-05-29 87
-
2025-06-04 115
-
SpringBoot集成WebSocket【基于纯H5】进行点对点[一对一]和广播[一对多]实时推送
2025-05-29 99