nginx下TP5 隐藏入口文件+支持pathinfo模式+配置多项目根目录

首先说下项目目录情况  跟目录/usr/share/nginx/html/(别说怎么这么深  0.0)

html文件夹下面两个目录 pssh  pssh_shop 两个tp5项目分别对应两个二级域名

配置多项目就把server{} 在复制出来一套 修改对应的root路径就可以

下面放上配置文件(只有域名2那个项目隐藏入口文件了 )

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    client_max_body_size 20M;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {

        listen       80;
        server_name 域名1;
        location / {
            root   /usr/share/nginx/html/pssh/public/;
            try_files $uri $uri/ /index.php?$query_string;
            index index.php  index.html index.htm;
        }
        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html/pssh/public/;
        }
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #   root   /usr/share/nginx/html/pssh/public/;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #

        location ~ \.php($|/) {
                root           /usr/share/nginx/html/pssh/public/;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param   PATH_INFO $fastcgi_path_info;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }

}

server {

        listen       80;
        server_name 域名2;
        #匹配url中server_name之后的部分
        location / {
            root   /usr/share/nginx/html/pssh_shop/public/;
            try_files $uri $uri/ /index.php?$query_string;
            index index.php  index.html index.htm;
            #重写url 为了隐藏index.php
            if ( !-e $request_filename) {
                rewrite ^/(.*)$ /index.php/$1 last;
                break;
            }
        }
        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html/pssh_shop/public/;
        }
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #   root   /usr/share/nginx/html/pssh_shop/public/;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #

        location ~ \.php($|/) {
                root           /usr/share/nginx/html/pssh_shop/public/;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param   PATH_INFO $fastcgi_path_info;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }

}

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

上面配置完  tp5的public目录下的.htaccess文件改成

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>

我是这么配置好用了 , 也不清楚这么写对不对 正不正规。记录下就是为了方便以后再用。不喜勿喷。谢谢

时间: 2024-08-04 03:14:42

nginx下TP5 隐藏入口文件+支持pathinfo模式+配置多项目根目录的相关文章

Nginx 虚拟主机下支持Painfo并隐藏入口文件的完整配置

server { listen 80; server_name zuqiu.com; # 设置你的域名 index index.html index.htm index.php; root D:/wnmp/www/dev/zuqiu; # 设置你的程序路径 location ~ \.php { root D:/wnmp/www/dev/zuqiu; # 设置你的程序路径 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_p

Yii隐藏入口文件index.php

1.开启apache的mod_rewrite模块 #去掉LoadModule rewrite_module modules/mod_rewrite.so前的"#"符号 #如果是ubuntu系统,系统默认是开启rewrite的 cd /etc/apache2/mods-enabled #查看是否有rewrite.load链接文件,如果没有则建立链接文件 cd /etc/apache2/mods-enabled ln -s ../mods-available/rewrite.load re

CI 框架怎么去掉隐藏入口文件 index.php

当我重新接触一个框架的时候首先肯定要去掉入口文件,也就是index.php 这个东西在url上很不漂亮,而且每次我访问我的网站的时候都要打进去url里面.这样告诉一个去掉 CI框架里面入口文件的方法,其实也就是添加一个重定向操作.很多框架的操作的大同小异. 言归正转…. 1. LoadModule rewrite_module modules/mod_rewrite.so,把该行前的#去掉. 搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该

ThinkPHP隐藏入口文件的配置方法

Apache服务器默认是没有开启rewrite模块儿的,所以我们访问ThinkPHP站点时的URL路径一般都是像这样的: http://127.0.0.1/index.php/index/article/list.html 这里的index.php即为我们的站点入口文件,而为了实现更好的SEO优化,我们有必要将入口文件index.php隐藏,最终实现如下访问路径: http://127.0.0.1/index/article/list.html 第一步:首先,需要打开Apache服务器的配置文件

Apache 隐藏入口文件以及防盗链.htaccess 文件

RewriteEngine on # 隐藏入口文件 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [L] # 防止资源盗链 RewriteCond %{HTTP_REFERER} !^$ [NC] RewriteCond %{HTTP_REFERER} !football.com [NC] RewriteCond %{HTTP_REFE

如何隐藏入口文件

原始地址 http://localhost/XCMS/index.php?factory/data/?cid=11&mid=2 我想要变成 http://localhost/XCMS/factory/data/?cid=11&mid=2 怎么写法? RewriteEngine on RewriteRule !static|index\.html index.php 如何隐藏入口文件

nginx低版本不支持pathinfo模式,thinkphp针对此问题的解决办法

将一个thinkphp项目从apache环境移到nginx1.2上,怎奈,nginx这个版本默认不支持pathinfo模式 首先,编辑nginx的虚拟主机配置文件 location ~ .*.(php|php5)?$ { #原有代码 } if (!-e $request_filename) {   rewrite  ^(.*)$  /index.php?s=$1  last;   break;    } #去掉$是为了不匹配行末,即可以匹配.php/,以实现pathinfo #如果你不需要用到p

tp5更改入口文件到根目录的方法分享

tp5把入口文件放到了public目录中,对于服务器或者vps来说没啥,因为可以指定目录,但是对于虚拟主机就不行了,我们必须吧index.php这入口文件放到根目录,那么我么需要改一下相对的引入文件的路径就可以了,代码如下: // 定义应用目录 define('APP_PATH', __DIR__ . '/application/'); // 开启调试模式 define('APP_DEBUG', true); // 加载框架引导文件 require __DIR__ . '/thinkphp/st

TP5中隐藏入口文件的问题 - CSDN博客

使用phpstudy和linux部署的时候 tp5中的官方说明是在入口文件的同级目录下添加一个.htaccess文件 文件内容如下: <IfModule mod_rewrite.c>Options +FollowSymlinks -MultiviewsRewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php?/$1 [QSA