How to Change the Default Port Number of Nginx on CentOS 7.6
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.
Comments ( 1 )
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