Nginx - quan1997ap/angular-app-note GitHub Wiki
Cài nginx-centos:
Run : https://www.thegeekstuff.com/2011/07/install-nginx-from-source/
How to Install and Configure Nginx from Source on Linux
1. Download nginx
Download nginx from here, or use wget as shown below. The current stable version is nginx 1.0.5
cd
wget http://nginx.org/download/nginx-1.0.5.tar.gz
tar xvfz nginx-1.0.5.tar.gz
cd nginx-1.0.5
2. Install nginx
There are lot of options that you can pass to ./configure. To identify list of all the configuration options do the following.
./configure --help
To begin with, install nginx with the default configuration options by doing ./configure as shown below.
./configure
make
make install
3. Change the Default nginx Listen Port
Nginx is configured to listen by default on port 80. If you are installing this on a machine for testing purpose, that already has an apache server running, you should change the nginx listen port.
Similar to apache’s httpd.conf file, nginx has nginx.conf file located under /usr/local/nginx/conf.
In the server section of nginx.conf, change the port 80 to 8081.
# vi /usr/local/nginx/conf/nginx.conf
server {
listen 8081;
server_name localhost;
4. Start Nginx Server
- nginx executable is located under /usr/local/nginx/sbin directory. Just call this executable to start the nginx server.
cd /usr/local/nginx/sbin
./nginx
- Once you start this, you’ll see the nginx “master process” and “worker process” if you do ps.
# ps -ef | grep -i nginx
root 18596 13:16 nginx: master process ./nginx
nobody 18597 13:16 nginx: worker process
5. Stop Nginx Server
To stop the nginx server, do the following.
cd /usr/local/nginx/sbin
./nginx -s stop
To view the current version of nginx, do the following:
# ./nginx -v
nginx: nginx version: nginx/1.0.5
To debug issues, view the error.log and access.log files located under /usr/local/nginx/logs
# ls /usr/local/nginx/logs/
access.log
error.log
nginx.pid
6. Nginx logs
Mặc định nếu k config log. Thì sẽ ghi logs vào folder nginx
tail -n 20 access.log
7. Nginx https
Bước 1: Enable SSL Nếu cài mặc định sẽ bị lỗi
Bước 2: Update config. Phải run lệnh trong file cài nginx