I’m not sure whether anyone encounter the similar problem when installing Nginx where the installation folder is not your intended location and the ‘configure‘ command not working although you had re-generated the Makefile.
If I run the command: ./configure –prefix=/usr/local when installing NGINX, it will be automatically install the files to /usr/local directory and created several folders (e.g. conf, logs) into /usr/local directory. This is not what I want. The documentation stated that by default, Nginx will be installed in /usr/ local/nginx. I assume the installation will automatically create an ‘nginx‘ folder in /usr/local/ directory after the installation. I have no idea why it doesn’t work for me although there are several blogs mentioned that they able to installed it in /usr/local/nginx. Although I’m not sure whether this is the correct method to solve the problem but I decided to blog about this for my future reference.
Problem:
I would prefer the installation content in /usr/local/nginx instead of /usr/local because I hate unorganised files. Imagine the conf and logs folders in the directory without the information of the owner or the application.
- I tried to re-configure the path with the following command:
sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module
- Run the command:
make make install
- Run the command to check any invalid command argument:
nginx -V
YEE-MACBOOK:~ mychin$ nginx -V nginx version: nginx/1.6.2 built by clang 4.2 (clang-425.0.28) (based on LLVM 3.2svn) TLS SNI support enabled configure arguments: --prefix=/usr/local --with-http_ssl_module
My latest command for the prefix configuration not working. It’s still taking the old prefix configuration command.
- Verify the configuration file with the command:
nginx -t
YEE-MACBOOK:local mychin$ nginx -t nginx: [alert] could not open error log file: open() "/usr/local/logs/error.log" failed (2: No such file or directory) 2014/12/08 14:14:44 [emerg] 334#0: open() "/usr/local/conf/nginx.conf" failed (2: No such file or directory) nginx: configuration file /usr/local/conf/nginx.conf test failed
Nginx still taking the old location: /usr/local instead of new one. For this reason, those two files cannot be found.
Solution
I tried several methods such as removed all the files, re-extract the downloaded zip file and reinstalled the nginx from scratch but this does not work. Logically, it should work if you had removed the folder with the installed content, install everything from scratch with a new specified path using ./configure command and re-generate the Makefile.
The only thing I didn’t delete was ‘nginx‘ executable file located in /usr/local/sbin directory. By default, the nginx executable file will follow the path: prefix/sbin/. If the latest path configuration (/usr/local/nginx) is not taking into effective, it means the nginx still using the old executable file, which is in /usr/local/sbin directory. Also, please note that /usr/local/sbin has been specified in the $PATH variable. For this reason, the new executable file (/usr/local/nginx/sbin) will never work.
- Remove the old executable file.
cd /usr/local/sbin sudo rm nginx
- Ensure no more files related to nginx and the nginx command should be failed to work at the current stage.
YEE-MACBOOK:sbin mychin$ nginx -t -bash: /usr/local/sbin/nginx: No such file or directory YEE-MACBOOK:sbin mychin$ nginx -V -bash: /usr/local/sbin/nginx: No such file or directory
- Re-install the nginx but with this command:
sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module
The summary of the installation path and everything goes well:
nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"</li>
- Update the $PATH variable by making the entry in .bash_profile in home directory.
sudo vi ~/.bash_profile export PATH=/usr/local/nginx/sbin:$PATH
- For immediate result for the changes to take effective.
source ~/.bash_profile
- Ensure everything should be working well with the command:
YEE-MACBOOK:sbin mychin$ sudo nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
YEE-MACBOOK:sbin mychin$ nginx -V nginx version: nginx/1.6.2 built by clang 4.2 (clang-425.0.28) (based on LLVM 3.2svn) TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module