这篇文章主要讲解了“Nginx服务器多站点怎么配置”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“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;
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 文件了。下面给出一个范例
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 的几个常用命令:
启动
./Nginx
重启
./Nginx -s reload
ps -ef | grep Nginx # 查询Nginx主进程号
从容停止 kill -quit 主进程号
快速停止 kill -term 主进程号
强制停止 kill -9 Nginx
若Nginx.conf配置了pid文件路径,如果没有,则在logs目录下
kill -信号类型 '/usr/local/Nginx/logs/Nginx.pid'
判断配置文件是否正确
./Nginx -t
感谢各位的阅读,以上就是“Nginx服务器多站点怎么配置”的内容了,经过本文的学习后,相信大家对Nginx服务器多站点怎么配置这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程之家,小编将为大家推送更多相关知识点的文章,欢迎关注!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。