Step 1: Create a software source configuration file named nginx. Repo under the/etc/yum. Repos. d/directory.
The content of the nginx. Repo file is:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
Step 2: run the command Yum install nginx and follow the prompts to complete the installation;
Step 3: run the/etc/init. d/nginx start command to start the nginx service;
Step 4: Test. Enter the Server IP address in the browser to display the nginx welcome page;
Restart nginx command:
Service nginx restart;
Nginx-s reload;
Nginx installation path:/etc/nginx
Configuration File:/etc/nginx. conf
First, modify the/etc/nginx. conf file:
[[Email protected] nginx] # vi nginx. conf
User nginx;
Worker_processes 2;
Error_log/var/log/nginx/error. Log warn;
Pid/var/run/nginx. PID;
Events {
Worker_connections 1024;
}
HTTP {
Include/etc/nginx/mime. types;
Default_type application/octet-stream;
Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" "$ http_x_forwarded_for "';
Access_log/var/log/nginx/access. Log main;
Sendfile on;
# Tcp_nopush on;
Keepalive_timeout 65;
Gzip on;
Include/etc/nginx/CONF. d/*. conf;
# The name after upstream is used later. backend is used here.
upstream backend { server 127.0.0.1:8080; }
}
Modify the/etc/nginx/CONF. d File
[[Email protected] Conf. d] # vi default. conf
Server {
Listen 80;
SERVER_NAME localhost;
# Charset koi8-r;
# Access_log/var/log/nginx/log/host. Access. Log main;
# Location /{
# Root/usr/share/nginx/html;
# Index index.html index.htm;
#}
location /{proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://backend;}
# Look familiar with the last line of proxy_pass http: // backend. backend is the name defined in the previous upstream.
# Error_page 404/404 .html;
# Redirect server error pages to the static page/50x.html
#
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/usr/share/nginx/html;
}