John Davidson

Nginx & PHP with additional directories

0 comments
Message:


I have an Nginx server which will host a few websites that are being migrated from an Apache server.


One of the things I've been trying to figure out is how to include additional directories to look at when files are being called.


In Apache I can include the following in the vhost:



php_value include_path /sites/web-test1/vendor/webtoolkit/src:/sites/web-test1/private:/usr/share/php



And that works fine in Apache. But in Nginx, I have attempted to use



include /sites/web-test1/vendor/webtoolkit/src;



But that doesn't work. Can anyone shed some light on how this is performed?


So I included the following in my vhost, as per a recommendation:


fastcgi_param  PHP_VALUE  "include_path=/sites/web-test1/vendor/webtoolkit/src/includes";
fastcgi_param PHP_VALUE "include_path=/sites/web-test1/vendor/";
fastcgi_param PHP_VALUE "include_path=/sites/web-test1/private/";
fastcgi_param PHP_VALUE "include_path=/usr/share/php/";

Note that I tried that first line both with and without the 'includes' directory in the statement, but it seemed to make no difference. That first line is what is needed to call the file shown below.


If it makes a difference the file uses the following line:


<?php include('includes/emailpriv.inc.php'); ?>

But I still keep getting the same error:


php: PHP Warning:  include(includes/emailpriv.inc.php): failed to open stream: No such file or directory in /git/web-test1/public/emailpriv.html on line XX
php: PHP Warning: include(): Failed opening 'includes/emailpriv.inc.php' for inclusion (include_path='/usr/share/php') in /git/web-test1/public/emailpriv.html on line XX

nginx.conf


user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
worker_rlimit_nofile 102400;

events {
worker_connections 100000;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;

server_names_hash_max_size 512;
server_names_hash_bucket_size 128;

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

##
# SSL Settings
##

ssl_protocols TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

log_format dm '$host - $remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent"';

access_log /nginx/log/nginx/access.log dm;
error_log /nginx/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

And the vhost:


server {
server_tokens off;
client_max_body_size 100M;
server_name ws2.xxxxxxxxxxxx.com;
listen 443 ssl;

access_log /nginx/log/nginx/test1.access.log;
error_log /nginx/log/nginx/test1.error.log;

root /git/web-test1/public;
index index.php index.html;

location / {
try_files $uri $uri/ /index.html /index.php?$args;
}

location ~ \.(php|html|htm)$ {
try_files $uri =404/
include snippets/fastcgi-php.conf;
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # regular pool
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SERVER_NAME $host;
fastcgi_param PHP_VALUE "include_path=/sites/web-test1/vendor/webtoolkit/src/includes";
fastcgi_param PHP_VALUE "include_path=/sites/web-test1/vendor/";
fastcgi_param PHP_VALUE "include_path=/sites/web-test1/private/";
fastcgi_param PHP_VALUE "include_path=/usr/share/php/";
}
ssl_certificate /etc/letsencrypt/live/ws2.xxxxxxxxxxxx.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ws2.xxxxxxxxxxxxx.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
if ($host = ws2.xxxxxxxxxxxxxxx.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

listen 80;
server_name ws2.xxxxxxxxxxxx.com;
return 404; # managed by Certbot

}


My Answer:
Nginx is a popular open-source web server and reverse proxy server that is known for its high performance, stability, and scalability. It is commonly used to serve static content, handle SSL/TLS termination, load balancing, and caching. Nginx is often used in conjunction with other web servers such as Apache to improve performance and efficiency. It is widely used by websites and web applications to handle high traffic loads and deliver content quickly and efficiently.

Rate this post

4 of 5 based on 3857 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us