• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News 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
{{postValue.id}}

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
{{postCtrl.cmtErrMsg}}

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

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 Ryan ?
how to use visual traceroute tool

Am using traceroute command to check for the route. i got this tool while surfing. So pls help me out installation and usage of Visual traceroute tool.

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.