yum安装的nginx配置

本文详细介绍了如何在NGINX中配置虚拟主机,包括网站目录设置、配置文件编辑、不带www域名的301跳转以及通过实践进行验证的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装后,NGINX的网站目录位于:
/usr/share/nginx/html
NGINX的配置文件位于:
/etc/nginx/nginx.conf

nginx -t              测试配置文件
nginx -v             查看相关版本

二、配置虚拟主机
在APACHE上配置虚拟主机。想来各位都有一定的体验。那如何在NGINX中实现呢?

[root@tianqiaodi html]# vi /etc/nginx/nginx.conf


cd /usr/share/nginx/html


mkdir tianqiaodi.com


把下面这段加在最后一个}之前:

server {
      listen       80;
      server_name  tianqiaodi.com www.tianqiaodi.com;
      location / {
      root   /usr/share/nginx/html/tianqiaodi.com;
      index  index.php index.html;
      }
      error_page  404              /404.html;
      location = /404.html {
      root   /usr/share/nginx/html;
      }
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
      root   /usr/share/nginx/html;
     }
      location ~ \.php$ {
      root           html/tianqiaodi.com/;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      include        /etc/nginx/fastcgi.conf;

      }

 }


不带www的域名加301跳转
如果不带www的域名要加301跳转,那也是和绑定域名一样,先绑定不带www的域名,只是不用写网站目录,而是进行301跳转,如:


server
{
listen80;
server_nameyour-domain.com;
rewrite ^/(.*) http://www.your-domain.com/$1 permanent;
}


/etc/init.d/nginx  restart  #重启nginx

测试篇
cd /usr/share/nginx/html/   #进入nginx默认网站根目录
vi  index.php   #新建index.php文件

<?php
     phpinfo();

?>

mkdir tianqiaodi.com #新建文件夹

:wq! #保存


重启nginx


service nginx restart


查看开放的端口

netstat -tanp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值