nginx多个站点配置nginxapachenginxphpnginxrewrite
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了nginx多个站点配置nginxapachenginxphpnginxrewrite,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3917字,纯文字阅读大概需要6分钟。
内容图文
服务器地址:192.168.1.231域名:test1.com 目录:/www/test1.com
域名:test2.com 目录:/www/test2.com
该配置思路把2个站点 test1.com, test2.com 放到
nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 test1.com.conf,test2.com.conf,
并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx
实际操作:
[root@localhost ~]# mkdir /www/test1.com [root@localhost ~]# mkdir /www/test2.com [root@localhost ~]# cd /etc/nginx/ [root@localhost nginx]# mkdir vhosts [root@localhost nginx]# cd vhosts/ [root@localhost vhosts]# vi test1.com.conf #增加以下内容 server { listen 80; server_name test1.com www.test1.com; access_log /www/access_test1.log main; location / { root /www/test1.com; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.html; fastcgi_param SCRIPT_FILENAME /www/test1.com/$fastcgi_script_name; include fastcgi_params; } location ~ /.ht { deny all; } } [root@localhost vhosts]# vi test2.com.conf #增加以下内容 server { listen 80; server_name test2.com www.test2.com; access_log /www/access_test2.log main; location / { root /www/test2.com; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.html; fastcgi_param SCRIPT_FILENAME /www/test2.com/$fastcgi_script_name; include fastcgi_params; } location ~ /.ht { deny all; } }
修改nginx.conf
备份配置文件
[root@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf20160425 [root@localhost ~]# vi /etc/nginx/nginx.conf. #修改成以下内容 user nginx; worker_processes 1; # main server error log error_log /var/log/nginx/error.log ; pid /var/run/nginx.pid; events { worker_connections 1024; } # main server config 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"'; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; server { listen 80; server_name _; access_log /var/log/nginx/access.log main; server_name_in_redirect off; location / { root /usr/share/nginx/html; index index.html; } } # 这一行是加载上面的配置文件 include /etc/nginx/vhosts/*; } 重起nginx服务 [root@localhost ~]# service nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ] [root@localhost ~]#
下面我们进行测试是否成功
将nginx默认页面/usr/html/index.html 分别拷备到/www/test1.com和/www/test2.com里面
然后将index.html里面的内容分别改成test1.com和test2.com
测试机为windowns
修改host文件
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
192.168.1.231 www.test1.com
192.168.1.231 www.test2.com
在该服务器上分别打开www.test1.com
test1.com
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
在该服务器上分别打开www.test2.com
test2.com
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
测试成功!!!!!
以上就介绍了nginx 多个站点配置,包括了nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
内容总结
以上是互联网集市为您收集整理的nginx多个站点配置nginxapachenginxphpnginxrewrite全部内容,希望文章能够帮你解决nginx多个站点配置nginxapachenginxphpnginxrewrite所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。