首页 / NGINX / nginx中配置虚拟主机
nginx中配置虚拟主机
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了nginx中配置虚拟主机,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2902字,纯文字阅读大概需要5分钟。
内容图文
![nginx中配置虚拟主机](/upload/InfoBanner/zyjiaocheng/1085/3f42b5523ab94fbc8a9d2a5b0e8492cd.jpg)
今天做了一个 nginx 的多虚拟主机的实验,遇到了一些问题。首先介绍一下配置文件如何修改。如下是我的主配置文件 nginx.conf
user nobodynobody;
worker_processes2;
error_log/usr/local/nginx/logs/nginx_error.log crit;
pid/usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include /usr/local/nginx/conf/vhosts/*.conf;
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip ‘$remote_addr$http_x_forwarded_for [$time_local]‘
‘$host "$request_uri" $status‘
‘"$http_referer""$http_user_agent"‘;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path/usr/local/nginx/client_body_temp;
proxy_temp_path/usr/local/nginx/proxy_temp;
fastcgi_temp_path/usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plainapplication/x-javascript text/css text/htm application/xml;
}
在主配置文件中不放 server 段的信息。然后在主配置文件添加一行 include/usr/local/nginx/conf/vhosts/*.conf; 这样,我们就可以在 conf/vhosts 目录下创建虚拟主机配置文件了。我所添加的路径是灵活的,根据本机不同的情况进行修改。
我创建了三个虚拟主机配置文件分别为 123.conf,456.conf,789.conf 。
123.conf 如下:
server
{
listen 80;
server_name www.123.com;
index index.html index.htm index.php;
root /var/123;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME/var/123$fastcgi_script_name;
}
}
456.conf 如下:
server
{
listen 80 default_server;
server_name www.456.com www.456.wangdi.com;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name;
}
}
789.conf
server
{
listen 80 ;
server_name www.789.com;
index index.html index.htm index.php;
root /var/789;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME/var/789$fastcgi_script_name;
}
}
由于我是在本地测试,所以在本地的 /etc/hosts 中添加域名
主机上也增加了 IP 地址
在配置文件的所在路径创建 index.php 文件,例如:
<?php
echo "this is 789";
?>
重启 nginx 和 php-fpm
service nginxrestart ; service php-fpm restart
然后访问这三个虚拟主机就可以了。
原文:http://881955.blog.51cto.com/871955/1655956
内容总结
以上是互联网集市为您收集整理的nginx中配置虚拟主机全部内容,希望文章能够帮你解决nginx中配置虚拟主机所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。