首页 > 代码库 > LNMP-Nginx默认虚拟主机
LNMP-Nginx默认虚拟主机
与httpd类似,第一个被Nginx加载的虚拟主机就是默认主机。但与之不同的是,它还有一个配置用来标记默认虚拟主机。
1、编辑nginx.conf
[root@juispan conf]# vi /usr/local/nginx/conf/nginx.conf 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; } } include vhost/*.conf; ##增加改行 }
2、编辑default.conf
[root@juispan conf]# mkdir /usr/local/nginx/conf/vhost [root@juispan conf]# cd !$;vi default.conf server { listen 80 default_server; server_name aaa.com; index index.html index.htm index.php; root /data/wwwroot/default; }
3、检查与启动
[root@juispan vhost]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@juispan vhost]# /usr/local/nginx/sbin/nginx -s reload
4、测试效果
[root@juispan vhost]# mkdir -p /data/wwwroot/default/ [root@juispan vhost]# echo “This is a default site.”>/data/wwwroot/default/index.html [root@juispan vhost]# curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> [root@juispan vhost]# curl -x127.0.0.1:80 123.com “This is a default site.”
本文出自 “Gorilla City” 博客,请务必保留此出处http://juispan.blog.51cto.com/943137/1955284
LNMP-Nginx默认虚拟主机
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。