How to change ports of Apache running behind Nginx

Created:

2016-11-16 12:48:04 UTC

Modified:

2017-08-16 17:08:28 UTC

2

Was this article helpful?


Have more questions?

Submit a request

How to change ports of Apache running behind Nginx

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk 11.x for Linux
  • Plesk 12.0 for Linux

Symptoms

How to change ports of Apache running behind Nginx?

Resolution

Nginx can be installed as a reverse proxy server in front of Apache. The Nginx process runs on ports 80 and 443. It accepts all HTTP(s) requests and forwards them to Apache, which runs on ports 7080 and 7081. Check the Administrator's Guide for more details about Nginx.

# netstat -ntpl |grep httpd
tcp 0 0 :::7080 :::* LISTEN 31773/httpd
tcp 0 0 :::7081 :::* LISTEN 31773/httpd

Use the instructions below to change the default Apache ports 7080/7081 to others (for example, to ports 8080/8081).

  1. If you want to change the default ports to 8080/8081, change port listening in the Apache configuration files as follows:

  2. Replace Listen 7080 with Listen 8080 in the /etc/httpd/conf/httpd.conf file.

  3. Replace Listen 7081 with Listen 8081 in the /etc/httpd/conf.d/ssl.conf file.

  4. Set new port values for the custom domain templates:

  5. To change the Apache HTTP port:Find all occurrences of the string $VAR->server->webserver->httpPort and replace them with the new port number enclosed in quotation marks (e.g., "8080").

  6. To change the Apache HTTPS port:Find all occurrences of the string $VAR->server->webserver->httpsPort and replace them with the new port number enclosed in quotation marks (e.g., "8081").

    Do not change the default templates. To introduce your changes to the configuration, copy the templates you need to the /usr/local/psa/admin/conf/templates/custom/ directory and modify them, preserving the directory structure. Then modify these copies. You can create new templates from scratch and place them in the custom/ directory according to the default structure.

    You can use the sed utility for quick replacement:

    # cd /usr/local/psa/admin/conf/templates
    cp -a default custom
    cd custom
    find . -type f | xargs sed -r -i~ 's/\\{?\\$VAR->server->webserver->httpPort\\}?/8080/g'
    find . -type f | xargs sed -r -i~ 's/\\{?\\$VAR->server->webserver->httpsPort\\}?/8081/g'
  7. Update the domain configuration:

    /usr/local/psa/admin/sbin/httpdmng --reconfigure-all
  8. Restart the Apache and Nginx services:

    # /etc/init.d/httpd restart
    # /etc/init.d/nginx restart
  9. Verify that the changes have been applied:

    # netstat -ntpl |grep httpd
    tcp 0 0 :::8080 :::* LISTEN 8650/httpd
    tcp 0 0 :::8081 :::* LISTEN 8650/httpd

These instructions are also described in the Advanced Administrator's guide .

Have more questions? Submit a request
Please sign in to leave a comment.