我正尝试将一些运行Apache和mod_php的旧版服务器的网站迁移到使用PHP-FPM的Nginx和PHP 7的新服务器上。 这两个网站都在域的根目录下运行一个PHP购物车,并在子文件夹/ news中运行一个wordpress博客。 现在,在旧服务器上,press blog这个词就在一个名为news的文件夹中(因此与购物车文件混合在一起)放在新服务器上,我想将它们分开,以便每个应用程序都可以在其中拥有单独的文件夹,以便:
/ home / www / sitename / cart / htdocs中的文件位于https://www.site.tld/
和
/ home / www / sitename / wordpress / htdocs中的文件可在https://www.site.tld/news/上find
我还希望能够使用不同的PHP-FPM池来提高安全性,如果需要允许我使用PHP 5池运行任一应用程序,直到它可以更新为在PHP 7上运行。
我已经接近了,但它一直试图从/home/www/sitename/wordpress/htdocs//news/test.php加载/news/test.php而不是/ home / www / manicpanic / wordpress / htdocs / test。 PHP。
configuration:
server { listen iphere:443 ssl http2; #ssl conf root /home/www/sitename/cart/htdocs; server_name site.tld www.site.tld; rewrite ^(.*)\.v[\d]+\.(css|js|png)$ $1.$2; location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { expires 30d; add_header Pragma public; add_header Cache-Control "public"; } location / { index index.php index.html index.htm; try_files $uri $uri/ /index.html; } location /news { alias /home/www/sitename/wordpress/htdocs; location ~ \.php$ { fastcgi_pass unix:/run/php/php7.0-fpm-wordpress.sock; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param APPLICATION_ENV production; include fastcgi_params; fastcgi_index index.php; fastcgi_param PHP_VALUE default_charset=ISO-8859-1; } } location ~ [^/]\.php(/|$) { fastcgi_pass unix:/run/php/php7.0-fpm-cart.sock; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param APPLICATION_ENV production; include fastcgi_params; fastcgi_index index.php; fastcgi_param PHP_VALUE default_charset=ISO-8859-1; } }
正则expression式location ~ [^/]\.php(/|$)将优先于前缀location /news , 除非使用^~修饰符。 请参阅此文档了解更多
location ^~ /news { alias /home/www/sitename/wordpress/htdocs; location ~ \.php$ { ... include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; ... } }
另外,不能将$document_root$fastcgi_script_name与alias一起使用,因为它会创build错误的path名。 改用$request_filename 。
总是include fastcgi_params; 在使用特定的fastcgi_param指令之前 ,否则特定的设置可能会被无声地覆盖。