Installing Nginx 1.6.3 on CentOS 6.5
To set up Nginx 1.6.3 on CentOS 6.5, follow these detailed steps:
Step 1: Add EPEL Repository
First, we need to download and install the EPEL repository, which provides additional packages.
[Root @ nginx /] # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
Step 2: Download Nginx 1.6.3
Next, download the Nginx 1.6.3 source package.
[Root @ nginx /] # wget http://nginx.org/download/nginx-1.6.3.tar.gz
Step 3: Prepare for Installation
Ensure that the necessary dependencies are installed.
[Root @ nginx /] # yum -y install pcre pcre-devel
[Root @ nginx /] # yum -y install openssl openssl-devel
[Root @ nginx /] # yum -y install gcc gcc-c++
Step 4: Decompress the Package
Extract the downloaded Nginx package.
[Root @ nginx /] # tar zxvf nginx-1.6.3.tar.gz
[Root @ nginx /] # cd nginx-1.6.3
[Root @ nginx nginx-1.6.3] # pwd
Step 5: Create a User for Nginx
Create a new user named nginx without a login shell.
[Root @ nginx nginx-1.6.3] # useradd nginx -s /sbin/nologin -M
Step 6: Configure, Compile, and Install Nginx
Run the configuration script and then compile and install Nginx.
[Root @ nginx nginx-1.6.3] # ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[Root @ nginx nginx-1.6.3] # make && make install
Step 7: Start Nginx
Verify the installation and start the Nginx service.
[Root @ nginx nginx-1.6.3] # /usr/local/nginx/sbin/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
[Root @ nginx nginx-1.6.3] # /usr/local/nginx/sbin/nginx
Check the status of the Nginx service using netstat.
[Root @ nginx nginx-1.6.3] # netstat -lntup | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3556/nginx
Step 8: Access Nginx
Access Nginx through your browser.
http://192.168.161.134
If you encounter issues, ensure that the firewall is turned off or modified to allow traffic on port 80.
[Root @ nginx nginx-1.6.3] # /etc/init.d/iptables stop
[Root @ nginx nginx-1.6.3] # iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[Root @ nginx nginx-1.6.3] # /etc/init.d/iptables save
Alternatively, you can use curl to test the setup.
[Root @ nginx nginx-1.6.3] # curl 192.168.161.134
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>. Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Step 9: Modify Nginx Configuration
Edit the nginx.conf file to customize your setup.
[Root @ nginx nginx-1.6.3] # cd /usr/local/nginx/conf/
[Root @ nginx conf] # vim nginx.conf
Example configuration:
user nginx;
worker_processes 1;
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 logs/access.log main;
sendfile on;
tcp_nopush on;
gzip on;
server {
listen 80;
server_name www.httpd.com;
charset utf-8;
access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
By following these steps, you should have a fully functional Nginx 1.6.3 server running on CentOS 6.5. If you have any questions or need further assistance, feel free to reach out.