Gentoo installation configuration Nginx+PHP
Installing Nginx in Gentoo is a very simple thing, but you need to do some configuration, otherwise nginx will not run.
Because Gentoo is entirely controlled by individuals, the following errors will occur when installing nginx if you need to manually configure which modules you need to install if you do not configure them.
unknown directive "autoindex" in /etc/nginx/nginx.conf:15
There are three main types of modules.
1.NGINX_MODULES_HTTP
2.NGINX_MODULES_MAIL
3.NGINX_ADD_MODULES
The configuration of these three types of modules needs to be configured in / etc/protage/make.conf
For example, if we want to install gzip and directory browsing modules, we need to configure the following in the configuration file
NGINX_MODULES_HTTP="fastcgi gzip autoindex"
Then you can install it through emerge-av nginx, where the above gzip module must be configured otherwise nginx will not start and will report errors
unknown directive "gzip" in /etc/nginx/nginx.conf:30
This is because we set the gzip option off in the configuration file, and we did not install the gzip module, so there will be an error. At the same time, we also enabled the directory browsing function of the website.
Look at our configuration file at this time.
user nginx nginx;
worker_processes 1;
error_log /var/log/nginx/error_log info;
events {
worker_connections 1024;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
client_header_timeout 10m;
client_body_timeout 10m;
send_timeout 10m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 4 2k;
request_pool_size 4k;
gzip off;
output_buffers 1 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75 20;
ignore_invalid_headers on;
index index.html;
server {
listen 127.0.0.1;
server_name localhost;
location / {
autoindex on;
autoindex_localtime on; #Enable directory browsing
}
access_log /var/log/nginx/localhost.access_log main;
error_log /var/log/nginx/localhost.error_log info;
#My own document catalogue
root /home/jacky/jianguoyun/WAMP/www;
}
# SSL example
#server {
# listen 127.0.0.1:443;
# server_name localhost;
# ssl on;
# ssl_certificate /etc/ssl/nginx/nginx.pem;
# ssl_certificate_key /etc/ssl/nginx/nginx.key;
# access_log /var/log/nginx/localhost.ssl_access_log main;
# error_log /var/log/nginx/localhost.ssl_error_log info;
# root /var/www/localhost/htdocs;
#}
}
At this point we start nginx
gentoo ~ # /usr/sbin/nginx
gentoo ~ # tail /var/log/nginx/error_log
At this point, you see the following
2017/11/30 16:47:54 [notice] 10378#0: using the "epoll" event method
2017/11/30 16:47:54 [notice] 10378#0: nginx/1.12.1
2017/11/30 16:47:54 [notice] 10378#0: OS: Linux 4.12.12-gentoo
2017/11/30 16:47:54 [notice] 10378#0: getrlimit(RLIMIT_NOFILE): 1024:4096
2017/11/30 16:47:54 [notice] 10379#0: start worker processes
2017/11/30 16:47:54 [notice] 10379#0: start worker process 10380
It means that nginx has been started successfully, and we can usually pass it at this time. http://localhost We visited it, but we encountered 403 errors here. Baidu may have the following directory permissions. I just set my file directory permissions to 755.
chmod 755 -R /home/jacky/jianguoyun/WAMP/www
PHP support
Nginx support for PHP needs to start fastcgi module when installing nginx, and add php-fpm module support when installing php.
echo "dev-lang/php fpm" >> /etc/portage/package.use/php
emerge -av php
After installing php, you need to add the configuration of PHP in nginx configuration file and add it on the basis of the original configuration file.
server {
listen 127.0.0.1;
server_name localhost;
location / {
autoindex on;
autoindex_localtime on; #Enable directory browsing
}
access_log /var/log/nginx/localhost.access_log main;
error_log /var/log/nginx/localhost.error_log info;
#My own document catalogue
root /home/jacky/jianguoyun/WAMP/www;
#php
location ~ \.php$ {
#try_files $uri =404;
include /etc/nginx/fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
In this way, we have completed the basic php environment support and created a new test.php file under the nginx document directory.
<html>
<head><title>test</title></head>
<body>
<?php
phpinfo();
?>
</body>
</html>
Accessing this php file verifies that nginx support for php has been successful