nginx keeps redirecting to some weird default port other than 80, 443. using wordpress here









up vote
0
down vote

favorite












I have followed the steps of configuring SSL certificate with nginx. However, after configuration it automatically keeps redirecting to port number 8899, which is neither related to http or https port.



Of course, before using certbot commands to setup the SSL certificates and letting certbot automatically update my nginx .conffiles, I was using port number 8899 to server my wordpress website. And at the time, it did work purely in http.



After certbot setup, I have change my nginx configuration files to work only on port 80, 443. However, even though I have double checked that there is no metion of port 8899 in any of my nginx conf files, the running nginx keeps redirecting to port 8899 whenever I attempt to access through port 80 or 443.



I have tried restarting the nginx service, and rebooting the machine. These atttempts failed to remove this weird symptom.



I would appreciate if anyone could nudge me any hints on solving this problem.



Below are my nginx configuration files.



/etc/nginx/nginx.conf



user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events
worker_connections 768;
# multi_accept on;


http

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;



#mail
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server
# listen localhost:110;
# protocol pop3;
# proxy on;
#
#
# server
# listen localhost:143;
# protocol imap;
# proxy on;
#
#


/etc/nginx/sites-enabled/mysite.net



server 
listen 80;
listen [::]:80;

# 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
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: 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 /home/ubuntu/data/wordpress/wordpress;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

server_name mysite.net;

client_max_body_size 50M;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
index index.php;


# pass PHP scripts to FastCGI server
#
location ~ .php$
#include snippets/fastcgi-php.conf;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;


# 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;
#

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot




UPDATE



I have found out that for some reason, when I try to access with 443 , then it will respond with a 301 redirect to port 8899.



However, there is no redirection commands in any of my nginx configuration file except from 80->443.



Here is my latest mysite.net nginx conf file



server 
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;


server
listen 443 ssl ;
listen [::]:443 ssl ;


# 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
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: 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;

server_name mysite.net;
root /home/ubuntu/data/wordpress/wordpress;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;



client_max_body_size 50M;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.


try_files $uri $uri/ =404;
index index.php;


# pass PHP scripts to FastCGI server
#
location ~ .php$
#include snippets/fastcgi-php.conf;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-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;
#

#listen [::]:443 ssl ipv6only=on; # managed by Certbot
#listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot










share|improve this question























  • Sounds like a browser's cache problem to me. Have you tried curl http://localhost//? If this still gives you a redirect, then you need to see your nginx's log.
    – sipp11
    Nov 11 at 6:48










  • @sipp11 I have updated the question. It looks like a redirection from 443->8899 is occuring somewhere. And this redirection does appear in the /var/log/nginx/access.log . But I really did not define any redirections from 443->8899 anywhere. The only configuration files that are in motions are: /etc/nginx/nginx.conf , /etc/nginx/sites-enable/mysite.net /etc/letsencrypt/options-ssl-nginx.conf
    – kwagjj
    Nov 11 at 7:25











  • @sipp11 an all of these three files have no commands that mention 8899... Any guesses where I might be missing?
    – kwagjj
    Nov 11 at 7:26










  • Is there anything in /etc/nginx/conf.d/? If nothing, then I think you have to update your wordpress URL to :80 too.. That should be the reason.
    – sipp11
    Nov 11 at 7:33










  • @sipp11 my god. you were right. The wordpress had "example.net:8899" set as its siteurl and home in wp_options table in the mysql db it was using. I changed both of them to https://example.net and it works now.. nginx configuration was not the problem after all. I did not know that wordpress would be the problem since it look so isolated from the nginx server stuff. Thank you again :)
    – kwagjj
    Nov 11 at 7:46














up vote
0
down vote

favorite












I have followed the steps of configuring SSL certificate with nginx. However, after configuration it automatically keeps redirecting to port number 8899, which is neither related to http or https port.



Of course, before using certbot commands to setup the SSL certificates and letting certbot automatically update my nginx .conffiles, I was using port number 8899 to server my wordpress website. And at the time, it did work purely in http.



After certbot setup, I have change my nginx configuration files to work only on port 80, 443. However, even though I have double checked that there is no metion of port 8899 in any of my nginx conf files, the running nginx keeps redirecting to port 8899 whenever I attempt to access through port 80 or 443.



I have tried restarting the nginx service, and rebooting the machine. These atttempts failed to remove this weird symptom.



I would appreciate if anyone could nudge me any hints on solving this problem.



Below are my nginx configuration files.



/etc/nginx/nginx.conf



user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events
worker_connections 768;
# multi_accept on;


http

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;



#mail
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server
# listen localhost:110;
# protocol pop3;
# proxy on;
#
#
# server
# listen localhost:143;
# protocol imap;
# proxy on;
#
#


/etc/nginx/sites-enabled/mysite.net



server 
listen 80;
listen [::]:80;

# 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
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: 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 /home/ubuntu/data/wordpress/wordpress;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

server_name mysite.net;

client_max_body_size 50M;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
index index.php;


# pass PHP scripts to FastCGI server
#
location ~ .php$
#include snippets/fastcgi-php.conf;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;


# 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;
#

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot




UPDATE



I have found out that for some reason, when I try to access with 443 , then it will respond with a 301 redirect to port 8899.



However, there is no redirection commands in any of my nginx configuration file except from 80->443.



Here is my latest mysite.net nginx conf file



server 
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;


server
listen 443 ssl ;
listen [::]:443 ssl ;


# 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
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: 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;

server_name mysite.net;
root /home/ubuntu/data/wordpress/wordpress;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;



client_max_body_size 50M;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.


try_files $uri $uri/ =404;
index index.php;


# pass PHP scripts to FastCGI server
#
location ~ .php$
#include snippets/fastcgi-php.conf;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-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;
#

#listen [::]:443 ssl ipv6only=on; # managed by Certbot
#listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot










share|improve this question























  • Sounds like a browser's cache problem to me. Have you tried curl http://localhost//? If this still gives you a redirect, then you need to see your nginx's log.
    – sipp11
    Nov 11 at 6:48










  • @sipp11 I have updated the question. It looks like a redirection from 443->8899 is occuring somewhere. And this redirection does appear in the /var/log/nginx/access.log . But I really did not define any redirections from 443->8899 anywhere. The only configuration files that are in motions are: /etc/nginx/nginx.conf , /etc/nginx/sites-enable/mysite.net /etc/letsencrypt/options-ssl-nginx.conf
    – kwagjj
    Nov 11 at 7:25











  • @sipp11 an all of these three files have no commands that mention 8899... Any guesses where I might be missing?
    – kwagjj
    Nov 11 at 7:26










  • Is there anything in /etc/nginx/conf.d/? If nothing, then I think you have to update your wordpress URL to :80 too.. That should be the reason.
    – sipp11
    Nov 11 at 7:33










  • @sipp11 my god. you were right. The wordpress had "example.net:8899" set as its siteurl and home in wp_options table in the mysql db it was using. I changed both of them to https://example.net and it works now.. nginx configuration was not the problem after all. I did not know that wordpress would be the problem since it look so isolated from the nginx server stuff. Thank you again :)
    – kwagjj
    Nov 11 at 7:46












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have followed the steps of configuring SSL certificate with nginx. However, after configuration it automatically keeps redirecting to port number 8899, which is neither related to http or https port.



Of course, before using certbot commands to setup the SSL certificates and letting certbot automatically update my nginx .conffiles, I was using port number 8899 to server my wordpress website. And at the time, it did work purely in http.



After certbot setup, I have change my nginx configuration files to work only on port 80, 443. However, even though I have double checked that there is no metion of port 8899 in any of my nginx conf files, the running nginx keeps redirecting to port 8899 whenever I attempt to access through port 80 or 443.



I have tried restarting the nginx service, and rebooting the machine. These atttempts failed to remove this weird symptom.



I would appreciate if anyone could nudge me any hints on solving this problem.



Below are my nginx configuration files.



/etc/nginx/nginx.conf



user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events
worker_connections 768;
# multi_accept on;


http

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;



#mail
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server
# listen localhost:110;
# protocol pop3;
# proxy on;
#
#
# server
# listen localhost:143;
# protocol imap;
# proxy on;
#
#


/etc/nginx/sites-enabled/mysite.net



server 
listen 80;
listen [::]:80;

# 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
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: 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 /home/ubuntu/data/wordpress/wordpress;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

server_name mysite.net;

client_max_body_size 50M;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
index index.php;


# pass PHP scripts to FastCGI server
#
location ~ .php$
#include snippets/fastcgi-php.conf;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;


# 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;
#

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot




UPDATE



I have found out that for some reason, when I try to access with 443 , then it will respond with a 301 redirect to port 8899.



However, there is no redirection commands in any of my nginx configuration file except from 80->443.



Here is my latest mysite.net nginx conf file



server 
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;


server
listen 443 ssl ;
listen [::]:443 ssl ;


# 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
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: 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;

server_name mysite.net;
root /home/ubuntu/data/wordpress/wordpress;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;



client_max_body_size 50M;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.


try_files $uri $uri/ =404;
index index.php;


# pass PHP scripts to FastCGI server
#
location ~ .php$
#include snippets/fastcgi-php.conf;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-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;
#

#listen [::]:443 ssl ipv6only=on; # managed by Certbot
#listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot










share|improve this question















I have followed the steps of configuring SSL certificate with nginx. However, after configuration it automatically keeps redirecting to port number 8899, which is neither related to http or https port.



Of course, before using certbot commands to setup the SSL certificates and letting certbot automatically update my nginx .conffiles, I was using port number 8899 to server my wordpress website. And at the time, it did work purely in http.



After certbot setup, I have change my nginx configuration files to work only on port 80, 443. However, even though I have double checked that there is no metion of port 8899 in any of my nginx conf files, the running nginx keeps redirecting to port 8899 whenever I attempt to access through port 80 or 443.



I have tried restarting the nginx service, and rebooting the machine. These atttempts failed to remove this weird symptom.



I would appreciate if anyone could nudge me any hints on solving this problem.



Below are my nginx configuration files.



/etc/nginx/nginx.conf



user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events
worker_connections 768;
# multi_accept on;


http

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;



#mail
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server
# listen localhost:110;
# protocol pop3;
# proxy on;
#
#
# server
# listen localhost:143;
# protocol imap;
# proxy on;
#
#


/etc/nginx/sites-enabled/mysite.net



server 
listen 80;
listen [::]:80;

# 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
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: 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 /home/ubuntu/data/wordpress/wordpress;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

server_name mysite.net;

client_max_body_size 50M;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
index index.php;


# pass PHP scripts to FastCGI server
#
location ~ .php$
#include snippets/fastcgi-php.conf;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;


# 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;
#

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot




UPDATE



I have found out that for some reason, when I try to access with 443 , then it will respond with a 301 redirect to port 8899.



However, there is no redirection commands in any of my nginx configuration file except from 80->443.



Here is my latest mysite.net nginx conf file



server 
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;


server
listen 443 ssl ;
listen [::]:443 ssl ;


# 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
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: 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;

server_name mysite.net;
root /home/ubuntu/data/wordpress/wordpress;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;



client_max_body_size 50M;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.


try_files $uri $uri/ =404;
index index.php;


# pass PHP scripts to FastCGI server
#
location ~ .php$
#include snippets/fastcgi-php.conf;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-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;
#

#listen [::]:443 ssl ipv6only=on; # managed by Certbot
#listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot







wordpress nginx certbot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 15:03

























asked Nov 11 at 6:06









kwagjj

256214




256214











  • Sounds like a browser's cache problem to me. Have you tried curl http://localhost//? If this still gives you a redirect, then you need to see your nginx's log.
    – sipp11
    Nov 11 at 6:48










  • @sipp11 I have updated the question. It looks like a redirection from 443->8899 is occuring somewhere. And this redirection does appear in the /var/log/nginx/access.log . But I really did not define any redirections from 443->8899 anywhere. The only configuration files that are in motions are: /etc/nginx/nginx.conf , /etc/nginx/sites-enable/mysite.net /etc/letsencrypt/options-ssl-nginx.conf
    – kwagjj
    Nov 11 at 7:25











  • @sipp11 an all of these three files have no commands that mention 8899... Any guesses where I might be missing?
    – kwagjj
    Nov 11 at 7:26










  • Is there anything in /etc/nginx/conf.d/? If nothing, then I think you have to update your wordpress URL to :80 too.. That should be the reason.
    – sipp11
    Nov 11 at 7:33










  • @sipp11 my god. you were right. The wordpress had "example.net:8899" set as its siteurl and home in wp_options table in the mysql db it was using. I changed both of them to https://example.net and it works now.. nginx configuration was not the problem after all. I did not know that wordpress would be the problem since it look so isolated from the nginx server stuff. Thank you again :)
    – kwagjj
    Nov 11 at 7:46
















  • Sounds like a browser's cache problem to me. Have you tried curl http://localhost//? If this still gives you a redirect, then you need to see your nginx's log.
    – sipp11
    Nov 11 at 6:48










  • @sipp11 I have updated the question. It looks like a redirection from 443->8899 is occuring somewhere. And this redirection does appear in the /var/log/nginx/access.log . But I really did not define any redirections from 443->8899 anywhere. The only configuration files that are in motions are: /etc/nginx/nginx.conf , /etc/nginx/sites-enable/mysite.net /etc/letsencrypt/options-ssl-nginx.conf
    – kwagjj
    Nov 11 at 7:25











  • @sipp11 an all of these three files have no commands that mention 8899... Any guesses where I might be missing?
    – kwagjj
    Nov 11 at 7:26










  • Is there anything in /etc/nginx/conf.d/? If nothing, then I think you have to update your wordpress URL to :80 too.. That should be the reason.
    – sipp11
    Nov 11 at 7:33










  • @sipp11 my god. you were right. The wordpress had "example.net:8899" set as its siteurl and home in wp_options table in the mysql db it was using. I changed both of them to https://example.net and it works now.. nginx configuration was not the problem after all. I did not know that wordpress would be the problem since it look so isolated from the nginx server stuff. Thank you again :)
    – kwagjj
    Nov 11 at 7:46















Sounds like a browser's cache problem to me. Have you tried curl http://localhost//? If this still gives you a redirect, then you need to see your nginx's log.
– sipp11
Nov 11 at 6:48




Sounds like a browser's cache problem to me. Have you tried curl http://localhost//? If this still gives you a redirect, then you need to see your nginx's log.
– sipp11
Nov 11 at 6:48












@sipp11 I have updated the question. It looks like a redirection from 443->8899 is occuring somewhere. And this redirection does appear in the /var/log/nginx/access.log . But I really did not define any redirections from 443->8899 anywhere. The only configuration files that are in motions are: /etc/nginx/nginx.conf , /etc/nginx/sites-enable/mysite.net /etc/letsencrypt/options-ssl-nginx.conf
– kwagjj
Nov 11 at 7:25





@sipp11 I have updated the question. It looks like a redirection from 443->8899 is occuring somewhere. And this redirection does appear in the /var/log/nginx/access.log . But I really did not define any redirections from 443->8899 anywhere. The only configuration files that are in motions are: /etc/nginx/nginx.conf , /etc/nginx/sites-enable/mysite.net /etc/letsencrypt/options-ssl-nginx.conf
– kwagjj
Nov 11 at 7:25













@sipp11 an all of these three files have no commands that mention 8899... Any guesses where I might be missing?
– kwagjj
Nov 11 at 7:26




@sipp11 an all of these three files have no commands that mention 8899... Any guesses where I might be missing?
– kwagjj
Nov 11 at 7:26












Is there anything in /etc/nginx/conf.d/? If nothing, then I think you have to update your wordpress URL to :80 too.. That should be the reason.
– sipp11
Nov 11 at 7:33




Is there anything in /etc/nginx/conf.d/? If nothing, then I think you have to update your wordpress URL to :80 too.. That should be the reason.
– sipp11
Nov 11 at 7:33












@sipp11 my god. you were right. The wordpress had "example.net:8899" set as its siteurl and home in wp_options table in the mysql db it was using. I changed both of them to https://example.net and it works now.. nginx configuration was not the problem after all. I did not know that wordpress would be the problem since it look so isolated from the nginx server stuff. Thank you again :)
– kwagjj
Nov 11 at 7:46




@sipp11 my god. you were right. The wordpress had "example.net:8899" set as its siteurl and home in wp_options table in the mysql db it was using. I changed both of them to https://example.net and it works now.. nginx configuration was not the problem after all. I did not know that wordpress would be the problem since it look so isolated from the nginx server stuff. Thank you again :)
– kwagjj
Nov 11 at 7:46












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Cheers to @sipp11, who help me in the comments to solve this.



The solution was to simply change the siteurl and home url in the wordpress mysql db. Nginx configuration had nothing to do with this issue.



nginx was doing its job properly. redirect 80 -> 443, and from 443 serve the files from my wordpress directory.



But since wordpress had been thinking http://example.com:8899 as the home url, I guess while processing the php files, it automatically triggered redirecting to port 8899.



That explains why the whole wordpress worked only when I connected port 8899 to an nginx server directive.



The reason why wordpress had http://example.com:8899 set as its siteurl and home in the first place was because of my first attempt of setting up wordpress under port 8899 as a test. At that time I changed the default port from 80 to 8899(because apache2 was using up port 80 and nginx kept failing to bind to port 80).






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246290%2fnginx-keeps-redirecting-to-some-weird-default-port-other-than-80-443-using-wor%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Cheers to @sipp11, who help me in the comments to solve this.



    The solution was to simply change the siteurl and home url in the wordpress mysql db. Nginx configuration had nothing to do with this issue.



    nginx was doing its job properly. redirect 80 -> 443, and from 443 serve the files from my wordpress directory.



    But since wordpress had been thinking http://example.com:8899 as the home url, I guess while processing the php files, it automatically triggered redirecting to port 8899.



    That explains why the whole wordpress worked only when I connected port 8899 to an nginx server directive.



    The reason why wordpress had http://example.com:8899 set as its siteurl and home in the first place was because of my first attempt of setting up wordpress under port 8899 as a test. At that time I changed the default port from 80 to 8899(because apache2 was using up port 80 and nginx kept failing to bind to port 80).






    share|improve this answer
























      up vote
      0
      down vote













      Cheers to @sipp11, who help me in the comments to solve this.



      The solution was to simply change the siteurl and home url in the wordpress mysql db. Nginx configuration had nothing to do with this issue.



      nginx was doing its job properly. redirect 80 -> 443, and from 443 serve the files from my wordpress directory.



      But since wordpress had been thinking http://example.com:8899 as the home url, I guess while processing the php files, it automatically triggered redirecting to port 8899.



      That explains why the whole wordpress worked only when I connected port 8899 to an nginx server directive.



      The reason why wordpress had http://example.com:8899 set as its siteurl and home in the first place was because of my first attempt of setting up wordpress under port 8899 as a test. At that time I changed the default port from 80 to 8899(because apache2 was using up port 80 and nginx kept failing to bind to port 80).






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Cheers to @sipp11, who help me in the comments to solve this.



        The solution was to simply change the siteurl and home url in the wordpress mysql db. Nginx configuration had nothing to do with this issue.



        nginx was doing its job properly. redirect 80 -> 443, and from 443 serve the files from my wordpress directory.



        But since wordpress had been thinking http://example.com:8899 as the home url, I guess while processing the php files, it automatically triggered redirecting to port 8899.



        That explains why the whole wordpress worked only when I connected port 8899 to an nginx server directive.



        The reason why wordpress had http://example.com:8899 set as its siteurl and home in the first place was because of my first attempt of setting up wordpress under port 8899 as a test. At that time I changed the default port from 80 to 8899(because apache2 was using up port 80 and nginx kept failing to bind to port 80).






        share|improve this answer












        Cheers to @sipp11, who help me in the comments to solve this.



        The solution was to simply change the siteurl and home url in the wordpress mysql db. Nginx configuration had nothing to do with this issue.



        nginx was doing its job properly. redirect 80 -> 443, and from 443 serve the files from my wordpress directory.



        But since wordpress had been thinking http://example.com:8899 as the home url, I guess while processing the php files, it automatically triggered redirecting to port 8899.



        That explains why the whole wordpress worked only when I connected port 8899 to an nginx server directive.



        The reason why wordpress had http://example.com:8899 set as its siteurl and home in the first place was because of my first attempt of setting up wordpress under port 8899 as a test. At that time I changed the default port from 80 to 8899(because apache2 was using up port 80 and nginx kept failing to bind to port 80).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 8:37









        kwagjj

        256214




        256214



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246290%2fnginx-keeps-redirecting-to-some-weird-default-port-other-than-80-443-using-wor%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党