• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to Change the Default Port Number of Nginx on CentOS 7.6

  • 00:38 netstat -tulpn | grep nginx
  • 00:55 vim /etc/nginx/nginx.conf
  • 01:19 nginx -t
  • 01:28 systemctl restart nginx.service
  • 01:38 netstat -tulpn | grep nginx
5714

Changing the default port number of Nginx on CentOS 7.6

Check the version of default port number of nginx using the following command.

[root@linuxhelp ~]# netstat -tulpn | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      32430/nginx: master 

Modify the configuration file of Nginx server to change the default port number

[root@linuxhelp ~]# vim /etc/nginx/nginx.conf 
user  nginx;
worker_processes  1;

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;

    server {
	listen       8989 default_server;
	listen       [::]:8989 default_server;
	server_name   _;
	root         /usr/share/nginx/html;
}
}

Test the configuration file of Nginx server.

[root@linuxhelp ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart the service of Nginx server.

[root@linuxhelp ~]# systemctl restart nginx.service 

Search for the listening socket 8989 using netstat.

[root@linuxhelp ~]# netstat -tulpn | grep 8989
tcp        0      0 0.0.0.0:8989            0.0.0.0:*               LISTEN      2260/nginx: master  
tcp6       0      0 :::8989                 :::*                    LISTEN      2260/nginx: master  

The default port number of Nginx (80) has changed to 8989 successfully and this tutorial comes to an end with this.

Tags:
ajinfernando
Author: 

Comments ( 1 )

angga92
I have followed step by step above,
but I stopped stuck on the system restart restart nginx
notif error : Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
after I edit / add in nano /etc/nginx/nginx.conf
beg for your help and enlightenment

thank you
Add a comment

Frequently asked questions ( 5 )

Q

What is the default port number of nginx server ?

A

the default port number of nginx server is 80

Q

What is load balancing in nginx server?

A

Load balancing in nginx server distributes incoming traffic across a group of backend servers.

Q

What is the use of load balancer in nginx server?

A

Load balancer is a device that acts as a reverse proxy and distributes the network or traffic across a number of servers which increases the capacitty abd reliability of applications that use nginx server.

Q

What is a reverse proxy cache in nginx server?

A

a reverse proxy in nginx server is a type of proxy server that typically sits behind the firewall in a private network and directs the clients requests to the appropriate backend server

Q

What are nginx server blocks ?

A

Server block in nginx server ables to host multiple websites on a single server

Related Tutorials in How to Change the Default Port Number of Nginx on CentOS 7.6

Related Tutorials in How to Change the Default Port Number of Nginx on CentOS 7.6

How To Install AnyDesk on Centos 7
How To Install AnyDesk on Centos 7
Apr 2, 2018
How to install Tiki Wiki CMS Groupware on CentOS 7
How to install Tiki Wiki CMS Groupware on CentOS 7
May 31, 2018
How to install PHP ImageMagick on CentOS 7
How to install PHP ImageMagick on CentOS 7
Nov 4, 2017
How to Upgrade and Downgrade the PHP Versions on CentOS 7.6
How to Upgrade and Downgrade the PHP Versions on CentOS 7.6
Jun 4, 2019
How to install Apache from Source Code on CentOS 7
How to install Apache from Source Code on CentOS 7
Oct 21, 2017
How to enable or disable repositories in CentOS
How to enable or disable repositories in CentOS
Mar 28, 2018
How to install AWStats on CentOS 7
How to install AWStats on CentOS 7
Dec 8, 2017
How to install Apache JMeter in CentOS 7
How to install Apache JMeter in CentOS 7
Mar 24, 2017

Related Forums in How to Change the Default Port Number of Nginx on CentOS 7.6

Related Forums in How to Change the Default Port Number of Nginx on CentOS 7.6

CentOS
connor class=
How To Completely Remove Apache package On CentOS 7.6
May 14, 2019
CentOS
ceriaimmaculate class=
setfacl : command not found
Jan 3, 2018
CentOS
mason class=
Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1)
Nov 20, 2018
Nginx
gokulravichandran2 class=
Failed to start A high performance web server and a reverse proxy server
Dec 23, 2018
CentOS
landon class=
Command to find SNMP Version
May 28, 2018
CentOS
arjitharon class=
cannot start minio service help
Mar 10, 2018
Apache tomcat
AadrikaAnshu class=
Cannot find ./catalina.sh The file is absent or does not have execute permission This file is needed to run this program
Jun 17, 2019
gitlab
caden class=
Insufficient space in download directory /var/cache/yum/x86_64/6/base/packages
Jul 22, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Ganesh Konka ?
Zentya 6.1 http proxy configuration

please send link for creating zentyal 6.1 for http proxy and firewall as gateway.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.