Mac Nginx installation environment configuration details
- 2020-05-13 04:29:22
- OfStack
Environmental information:
Mac OS X 10.11.1
Homebrew 0.9.5
The body of the
1. Install Nginx
1. Terminal execution:
brew search nginx
brew install nginx
Current version 1.6.2
After the installation, you can see some configuration paths in the terminal output information:
/ usr local etc/nginx/nginx conf (configuration file path)
/ usr local var/www the default path (server)
/ usr/local/Cellar nginx / 1.6.2 (seems to be the installation path)
2. Access localhost: 8080
Nginx defaults to port 8080, which is now accessible:
localhost:8080
There will be a default welcome screen.
3. Modify the php-fpm file
1. Execute the order:
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
2. Locate the php-fpm files in the directory
/private/etc/php-fpm.conf
3. Find the error_log in line 32 and change it to (replace the normal line, note '; 'and Spaces) :
error_log = /usr/local/var/log/php-fpm.log
Otherwise, php-fpm will report an error:
ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
4. Modify the Nginx configuration
1. Open the nginx.config file
/usr/local/etc/nginx/nginx.conf
2. Find the location configuration of server and add one index.php to index
location / {
root html;
index index.html index.htm index.php;
}
3. Open the commented location ~.php$(that is, delete the '#' in front of the code) below server, as follows:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
4. And modify the parameter fastcgi_param
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
Instead of
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
5. Create index. php
In/usr local/var/www directory, delete index. html, create index. php, input
<?php phpinfo(); ?>
6. Start relevant services
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
0
Then go to localhost:8080 and see the php configuration information to say ok
7. Other orders
After modifying nginx.conf, overload the configuration file
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
1
Stop the nginx server
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
2
Stop php-fpm can be stopped directly in Activity Monitor. You can also use a script to stop.
8. Possible problems
1. Visit index.php to report 403 Forbidden.see if, in step (4.2), index.php is added after index.
2. Visit index.php for File not found.see if the fastcgi_param parameter has been modified in (4.4).