首先说下项目目录情况 跟目录/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-10-08 22:58:44