After installing nginx, access the local ip, and the result will be reported directly. Then go to the nginx error log and see the following error message, which means that there is no error under html.
directory index of "/usr/share/nginx/html/" is forbidden
1. If there is no index.php,index.html under / usr/share/nginx/html, the domain name can not be accessed directly, and the file can not be found, 403 forbidden will be reported.
Solution: Enter the following commands directly:
#Delete the index.html file
rm /usr/share/nginx/html/index.html
#Create a new index.php file under the html directory, which contains`<?php phpinfo(); ?>` See phpinfo
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php
2. Another reason is that the location of your default nginx configuration file does not specify the root path, which is my problem.
This is added directly to the default server:
location / {
root html;
index index.php index.html index.htm;
}
3. If you still can't access it properly, go into the default configuration file of nginx to find out if there is any code as follows:
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
The above code means that the PHP file is handed over to php-fpm, which occupies a port number of 9000.
After configuring, remember to restart nginx, or reload it:
Restart nginx:
nginx -s stop
nginx
Or:
nginx -s reopen
Here is the configuration file for reloading nginx (recommended):
service nginx reload
Find the installation directory for nginx:
[root@localhost nginx]# which nginx
/usr/sbin/nginx #This is the default location for yum installation
View the command prompt for nginx:
[root@localhost nginx]# nginx -h
nginx version: nginx/1.10.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/share/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file