nginx服务器绑定多个域名、支持pathinfo路由、隐藏index.php入口文件

这篇文章仅仅是操作,解释说明部分待更新。

1. 修改nginx的配置文件(我的配置文件在/etc/nginx/nginx.conf)

[[email protected] ~]# find / -name nginx.conf      
[[email protected] ~]# vim /etc/nginx/nginx.conf    
nginx.conf配置文件的大致结构:
...
http{
    server{
    ...                      #一个server结构可以对应一个域名
    }
    include vhosts/*.conf    #增加这一句,以后所有新增的域名都可以放在/etc/nginx/vhosts/下,便于分开管理,注意vhosts目录需要创建
}

2. 在/etc/nginx/vhosts/目录下,新增新域名的配置文件xincanzhe.conf(这边我要绑定一个www.xincanzhe.top的域名),复制nginx.conf中的server部分到xincanzhe.conf

server {
        listen       80;
        server_name  www.xincanzhe.top;    #新增域名名称

        #charset koi8-r;

        access_log  /data/wwwlogs/www.xincanzhe.top.log  combined;    #设置访问该域名产生的日志文件,无需创建设置后会自动生成

        location / {
            root   /data/wwwroot/xincanzhe/public/;    #域名指向的根目录
            index  index.html index.php index.htm;
            #隐藏index.php
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /data/wwwroot/xincanzhe/public/;    #域名指向的根目录
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #使Nginx支持pathinfo路由
            fastcgi_split_path_info  ^(.+\.php)(.*)$;       #增加这一句
            fastcgi_param PATH_INFO  $fastcgi_path_info;    #增加这一句
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

3. 如果需要再次新增域名,只需要在/etc/nginx/vhosts/新建一个配置文件即可。

原文地址:https://www.cnblogs.com/xincanzhe/p/9031975.html

时间: 2024-08-10 00:40:29

nginx服务器绑定多个域名、支持pathinfo路由、隐藏index.php入口文件的相关文章

nginx支持pathinfo并且隐藏index.php

How To Set Nginx Support PATHINFO URL Model And Hide The /index.php/ 就像这样 The URL before setting like this: http://serverName/index.php?m=Home&c=Customer&a=getInformation&id=1 Now like this: http://serverName/Home/Customer/getInformation/id/1

nginx 404页面处理以及pathInfo和隐藏index.php总述

今天开发公司官网:http://www.zstime.com/,遇到一个问题,如何在nginx下设置pathInfo以及如何隐藏index.php 这里分别来讲解一下: 一.隐藏index.php 隐藏index.php需要修改nginx的配置文件,如果你是使用vhost的,需要修改如conf/vhost/你的文件名.conf 文件,整个文件如下 server { listen 80; server_name www.zstime.com; index index index.html inde

apache2虚拟主机实现一个服务器绑定多个域名

1.apache2的配置 首先要配置好apache2,如果未配置,请参考我之前的博文:lamp的配置 2.域名的解析 将全部域名的www和@的A记录解析到云服务器的IP 3.虚拟主机的配置 1.配置httpd.conf 如果etc/httpd/conf/httpd.conf存在,则配置此httpd.conf 如果etc/httpd/conf/httpd.conf不存在,此时需要我们在/etc/apache2下新建一个httpd.conf,配置此httpd.conf,然后 /etc/apache2

ThinkPHP中通过URL重写隐藏应用的入口文件index.php的相关服务器的配置

[ Apache ] 将httpd.conf配置文件中mod_rewrite.so所在行前面的‘#’去掉 AllowOverride None 将None改为 All 效果图

centos上安装nginx服务器实现虚拟主机和域名重定向

Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日.其将源代码以类BSD许可证的形式发布,因它的稳定性.丰富的功能集.示例配置文件和低系统资源的消耗而闻名.2011年6月1日,nginx 1.0.4发布. Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP

nginx不支持pathinfo函数

server { listen 80; server_name www.domain.com domain.com; error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location ~ \.php { root /data0/htdocs/www; fastcgi_pass 127.0.0.1:9000; #包含nginx服务器传递给fastcgi程序的参数,php中通过$_SERVER['参数名']可获取 inc

nginx不支持pathinfo模式解决方法

错误描述:1,打开网页,页面提示不支持pathinfo                  2,类似 index.php/hellworld 会提示找不到页面 解决办法:1,修改nginx.conf的server{} 中的内容下: 备注: 如果是在vhost配置下可单独添加在vhost配置文件下,如果没有vhost则在nginx.conf配置文件下添加 75         # pass the PHP scripts to FastCGI server listening on 127.0.0.

Nginx 之四: Nginx服务器的rewrite、全局变量、重定向和防盗链相关功能

一:Nginx 后端服务器组的配置: 1.upstream: 用于设置后端服务器组的主要指令,upstream类似于之前的server块或http块,用法如下: upstreame Myserver{ #ip_hash; #least_conn: #fair; #hash $request_uri; #hash_method crc32; server 192.168.0.2:8080 #weight 2 max_fails 3 fail_timeout 60; 192.168.0.3:8080

nginx服务器上遇到了acces denied,报错是fastCGI只要好好修改配置就行了

猜想: 懵逼 实践: 首先通用的方法,并没有解决问题. 1.修改php-fpm配置文件vim /etc/php-fpm.d/www.confuser = nginx        编辑用户为nginxgroup = nginx        修改组为nginx 2.修改目录权限chown nginx.nginx /usr/share/nginx/html/ -R #设置目录所有者chmod 700 /usr/share/nginx/html/ -R #设置目录权限 定位: 首先看报错: 2013