# Como alterar porta do apache e do nginx

**URL:** <https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262>\
**Category:** Sem categoria\
**Created:** [Dezembro 1, 2023, 3:55pm UTC](https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262 "2023-12-01T15:55:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://forum.ieducar.org/u/Silvio)\
**Post date:** [Dezembro 1, 2023, 3:55pm UTC](https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262/1 "2023-12-01T15:55:57Z")

</div>

Como alterar porta do apache e do nginx???

---

<div class="post-metadata">

**Author:** ![tiago.camargo](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.ieducar.org/tiago.camargo/32/148_2.png) [@tiago.camargo](https://forum.ieducar.org/u/tiago.camargo)\
**Post date:** [Dezembro 5, 2023, 12:35pm UTC](https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262/2 "2023-12-05T12:35:43Z")

</div>

Você pode encontrar essas informações na documentação dos dois produtos.

- [Module ngx\_http\_core\_module](https://nginx.org/en/docs/http/ngx_http_core_module.html#listen)
- [Binding to Addresses and Ports - Apache HTTP Server Version 2.4](https://httpd.apache.org/docs/2.4/bind.html)

---

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://forum.ieducar.org/u/Silvio)\
**Post date:** [Dezembro 5, 2023, 5:39pm UTC](https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262/3 "2023-12-05T17:39:48Z")

</div>

Achei esses dois scripts mais simples

> **[Alterando a porta Nginx no Linux – Acervo Lima](https://acervolima.com/alterando-a-porta-nginx-no-linux/)**
>
> O maior acervo de tutoriais e referências

> **[Como alterar a porta Apache HTTP no Linux? – Acervo Lima](https://acervolima.com/como-alterar-a-porta-apache-http-no-linux/)**
>
> O maior acervo de tutoriais e referências

Alterei mais ao tentar reiniciar o nginx não reinicia

---

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://forum.ieducar.org/u/Silvio)\
**Post date:** [Dezembro 7, 2023, 3:37pm UTC](https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262/4 "2023-12-07T15:37:38Z")

</div>

Quando tento reiniciar o nginx da o seguinte erro:  
root@vicediretora-Positivo-Master-D3200:/home/vicediretora# systemctl status nginx.service  
× nginx.service - A high performance web server and a reverse proxy server  
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:\>  
Active: failed (Result: exit-code) since Thu 2023-12-07 12:18:45 -03; 26s \>  
Docs: man:nginx(8)  
Process: 50062 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master\_proc\>  
Process: 50063 ExecStart=/usr/sbin/nginx -g daemon on; master\_process on; (\>  
CPU: 70ms

dez 07 12:18:43 vicediretora-Positivo-Master-D3200 systemd[1]: Starting A high \>  
dez 07 12:18:43 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:43 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:44 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:44 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 systemd[1]: nginx.service: C\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 systemd[1]: nginx.service: F\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 systemd[1]: Failed to start \>  
lines 1-18/18 (END)

Será que meu script está errado???

## 

# You should look at the following URL’s in order to grasp a solid understanding

# of Nginx configuration files in order to fully unleash the power of Nginx.

# [NGINX Documentation](https://www.nginx.com/resources/wiki/start/)

# [NGINX Documentation](https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/)

# [Nginx/DirectoryStructure - Debian Wiki](https://wiki.debian.org/Nginx/DirectoryStructure)

# 

# In most cases, administrators will remove this file from sites-enabled/ and

# leave it as reference inside of sites-available where it will continue to be

# updated by the nginx packaging team.

# 

# This file will automatically load configuration files provided by other

# applications, such as Drupal or Wordpress. These applications will be made

# available underneath a path with that package name, such as /drupal8.

# 

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

## 

# Default server configuration

# 

server {

listen 8082 default\_server;

listen [::]:8082 default\_server;

# SSL configuration

# 

# listen 443 ssl default\_server;

# listen [::]:443 ssl default\_server;

# 

# Note: You should disable gzip for SSL traffic.

# See: [https://bugs.debian.org/773332](https://bugs.debian.org/773332)

# 

# Read up on ssl\_ciphers to ensure a secure configuration.

# See: [https://bugs.debian.org/765782](https://bugs.debian.org/765782)

# 

# Self signed certs generated by the ssl-cert package

# Don’t use them in a production server!

# 

# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP

index index.html index.htm index.nginx-debian.html;

server\_name \_;

location / {

# First attempt to serve request as file, then

# as directory, then fall back to displaying a 404.

try\_files $uri $uri/ =404;

}

# pass PHP scripts to FastCGI server

# 

#location ~ .php$ {

# include snippets/fastcgi-php.conf;

# 

# # With php-fpm (or other unix sockets):

# fastcgi\_pass unix:/run/php/php7.4-fpm.sock;

# # With php-cgi (or other tcp sockets):

# fastcgi\_pass 127.0.0.1:9000;

#}

# deny access to .htaccess files, if Apache’s document root

# concurs with nginx’s one

# 

#location ~ /.ht {

# deny all;

#}

}

# Virtual Host configuration for [example.com](http://example.com)

# 

# You can move that to a different file under sites-available/ and symlink that

# to sites-enabled/ to enable it.

# 

#server {

# listen 8082;

# listen [::]:8082;

# 

# server\_name [example.com](http://example.com);

# 

# root /var/www/example.com;

# index index.html;

# 

# location / {

# try\_files $uri $uri/ =404;

# }

---

<div class="post-metadata">

**Author:** ![edersoares](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.ieducar.org/edersoares/32/1050_2.png) [@edersoares](https://forum.ieducar.org/u/edersoares)\
**Post date:** [Dezembro 26, 2023, 1:21pm UTC](https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262/5 "2023-12-26T13:21:49Z")

</div>

Ficou difícil de entender o código do seu Nginx, consegue estruturar melhor?

---

<div class="post-metadata">

**Author:** ![Silvio](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@Silvio](https://forum.ieducar.org/u/Silvio)\
**Post date:** [Dezembro 27, 2023, 10:36pm UTC](https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262/6 "2023-12-27T22:36:49Z")

</div>

root@vicediretora-Positivo-Master-D3200:/home/vicediretora# systemctl status nginx.service  
× nginx.service - A high performance web server and a reverse proxy server  
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:\>  
Active: failed (Result: exit-code) since Thu 2023-12-07 12:18:45 -03; 26s \>  
Docs: man:nginx(8)  
Process: 50062 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master\_proc\>  
Process: 50063 ExecStart=/usr/sbin/nginx -g daemon on; master\_process on; (\>  
CPU: 70ms

dez 07 12:18:43 vicediretora-Positivo-Master-D3200 systemd[1]: Starting A high \>  
dez 07 12:18:43 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:43 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:44 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:44 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 nginx[50063]: nginx: [emerg]\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 systemd[1]: nginx.service: C\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 systemd[1]: nginx.service: F\>  
dez 07 12:18:45 vicediretora-Positivo-Master-D3200 systemd[1]: Failed to start \>  
lines 1-18/18 (END)

Quando tento ver o status do nginx da erro. E não da start, nem restart e nem reload. O nginx da como failed. Eu alterei a porta do nginx para 8082. Pois quando digito o localhost so aparece apache2

---

<div class="post-metadata">

**Author:** ![edersoares](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.ieducar.org/edersoares/32/1050_2.png) [@edersoares](https://forum.ieducar.org/u/edersoares)\
**Post date:** [Janeiro 2, 2024, 12:18pm UTC](https://forum.ieducar.org/t/como-alterar-porta-do-apache-e-do-nginx/2262/7 "2024-01-02T12:18:44Z")

</div>

Esse tipo de erro foge um pouco da solução, seria interessante seguir um passo a passo do zero ou pedir ajuda a alguém que já tenha passado por esta situação.
