nginx default configuration file issue

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm using nginx as a proxy server at port 80 and 443 for ssl, Apache at port 8082, and Varnish at port 81



The purpose for using nginx to send http and https requests to varnish and then varnish will send it to Apache server.



Bellow is my defualt nginx file :



#Redirect http www to https no-www
server
server_name _;
access_log off;


#Redirect http no-www to https no-www
server
// listening to port 80
listen "actual-server-ip";
listen [::]:80;
server_name localhost;
root /home/maindir;
index index.php;
access_log off;
port_in_redirect off;

location /
allow 127.0.0.1;
auth_basic "Please enter username";
auth_basic_user_file /etc/nginx/.passfile1;




server
// listening to port 443 for https requests
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name localhost;
port_in_redirect off;
access_log off;
ssl_certificate /main/ssl/eth0___localhost.pem;
ssl_certificate_key /main/ssl/eth0___localhost.key;
ssl_trusted_certificate /main/ssl/eth0___localhost.ca;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /root/dhparams.pem;
ssl_prefer_server_ciphers on;
ssl_ecdh_curve secp384r1;
root /home/maindir;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
index index.php index.html index.htm;

location /
proxy_pass http://127.0.0.1:81; // to direct requests to varnish
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header HTTPS "on";
proxy_read_timeout 90;
proxy_connect_timeout 90;
proxy_redirect off;


location ~ /.ht
deny all;





But I have the following issues:



1- It does not direct http requests to https



2- it does not direct non-www to www



is the following command right:



proxy_pass http://127.0.0.1:81;



to direct requests from nginx to varnish or 127.0.0.1 should be actual server address?










share|improve this question









New contributor




Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Other than the redirection part, does the proxy configuration work without any problems? You'll probably need to set up redirection separately: serversforhackers.com/c/redirect-http-to-https-nginx
    – Haxiel
    Nov 21 at 4:27














up vote
0
down vote

favorite












I'm using nginx as a proxy server at port 80 and 443 for ssl, Apache at port 8082, and Varnish at port 81



The purpose for using nginx to send http and https requests to varnish and then varnish will send it to Apache server.



Bellow is my defualt nginx file :



#Redirect http www to https no-www
server
server_name _;
access_log off;


#Redirect http no-www to https no-www
server
// listening to port 80
listen "actual-server-ip";
listen [::]:80;
server_name localhost;
root /home/maindir;
index index.php;
access_log off;
port_in_redirect off;

location /
allow 127.0.0.1;
auth_basic "Please enter username";
auth_basic_user_file /etc/nginx/.passfile1;




server
// listening to port 443 for https requests
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name localhost;
port_in_redirect off;
access_log off;
ssl_certificate /main/ssl/eth0___localhost.pem;
ssl_certificate_key /main/ssl/eth0___localhost.key;
ssl_trusted_certificate /main/ssl/eth0___localhost.ca;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /root/dhparams.pem;
ssl_prefer_server_ciphers on;
ssl_ecdh_curve secp384r1;
root /home/maindir;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
index index.php index.html index.htm;

location /
proxy_pass http://127.0.0.1:81; // to direct requests to varnish
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header HTTPS "on";
proxy_read_timeout 90;
proxy_connect_timeout 90;
proxy_redirect off;


location ~ /.ht
deny all;





But I have the following issues:



1- It does not direct http requests to https



2- it does not direct non-www to www



is the following command right:



proxy_pass http://127.0.0.1:81;



to direct requests from nginx to varnish or 127.0.0.1 should be actual server address?










share|improve this question









New contributor




Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Other than the redirection part, does the proxy configuration work without any problems? You'll probably need to set up redirection separately: serversforhackers.com/c/redirect-http-to-https-nginx
    – Haxiel
    Nov 21 at 4:27












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm using nginx as a proxy server at port 80 and 443 for ssl, Apache at port 8082, and Varnish at port 81



The purpose for using nginx to send http and https requests to varnish and then varnish will send it to Apache server.



Bellow is my defualt nginx file :



#Redirect http www to https no-www
server
server_name _;
access_log off;


#Redirect http no-www to https no-www
server
// listening to port 80
listen "actual-server-ip";
listen [::]:80;
server_name localhost;
root /home/maindir;
index index.php;
access_log off;
port_in_redirect off;

location /
allow 127.0.0.1;
auth_basic "Please enter username";
auth_basic_user_file /etc/nginx/.passfile1;




server
// listening to port 443 for https requests
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name localhost;
port_in_redirect off;
access_log off;
ssl_certificate /main/ssl/eth0___localhost.pem;
ssl_certificate_key /main/ssl/eth0___localhost.key;
ssl_trusted_certificate /main/ssl/eth0___localhost.ca;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /root/dhparams.pem;
ssl_prefer_server_ciphers on;
ssl_ecdh_curve secp384r1;
root /home/maindir;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
index index.php index.html index.htm;

location /
proxy_pass http://127.0.0.1:81; // to direct requests to varnish
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header HTTPS "on";
proxy_read_timeout 90;
proxy_connect_timeout 90;
proxy_redirect off;


location ~ /.ht
deny all;





But I have the following issues:



1- It does not direct http requests to https



2- it does not direct non-www to www



is the following command right:



proxy_pass http://127.0.0.1:81;



to direct requests from nginx to varnish or 127.0.0.1 should be actual server address?










share|improve this question









New contributor




Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm using nginx as a proxy server at port 80 and 443 for ssl, Apache at port 8082, and Varnish at port 81



The purpose for using nginx to send http and https requests to varnish and then varnish will send it to Apache server.



Bellow is my defualt nginx file :



#Redirect http www to https no-www
server
server_name _;
access_log off;


#Redirect http no-www to https no-www
server
// listening to port 80
listen "actual-server-ip";
listen [::]:80;
server_name localhost;
root /home/maindir;
index index.php;
access_log off;
port_in_redirect off;

location /
allow 127.0.0.1;
auth_basic "Please enter username";
auth_basic_user_file /etc/nginx/.passfile1;




server
// listening to port 443 for https requests
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name localhost;
port_in_redirect off;
access_log off;
ssl_certificate /main/ssl/eth0___localhost.pem;
ssl_certificate_key /main/ssl/eth0___localhost.key;
ssl_trusted_certificate /main/ssl/eth0___localhost.ca;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /root/dhparams.pem;
ssl_prefer_server_ciphers on;
ssl_ecdh_curve secp384r1;
root /home/maindir;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
index index.php index.html index.htm;

location /
proxy_pass http://127.0.0.1:81; // to direct requests to varnish
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header HTTPS "on";
proxy_read_timeout 90;
proxy_connect_timeout 90;
proxy_redirect off;


location ~ /.ht
deny all;





But I have the following issues:



1- It does not direct http requests to https



2- it does not direct non-www to www



is the following command right:



proxy_pass http://127.0.0.1:81;



to direct requests from nginx to varnish or 127.0.0.1 should be actual server address?







nginx reverse-proxy






share|improve this question









New contributor




Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 20 at 22:50









Rui F Ribeiro

38.2k1475125




38.2k1475125






New contributor




Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 20 at 22:30









Dany

1




1




New contributor




Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Dany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Other than the redirection part, does the proxy configuration work without any problems? You'll probably need to set up redirection separately: serversforhackers.com/c/redirect-http-to-https-nginx
    – Haxiel
    Nov 21 at 4:27
















  • Other than the redirection part, does the proxy configuration work without any problems? You'll probably need to set up redirection separately: serversforhackers.com/c/redirect-http-to-https-nginx
    – Haxiel
    Nov 21 at 4:27















Other than the redirection part, does the proxy configuration work without any problems? You'll probably need to set up redirection separately: serversforhackers.com/c/redirect-http-to-https-nginx
– Haxiel
Nov 21 at 4:27




Other than the redirection part, does the proxy configuration work without any problems? You'll probably need to set up redirection separately: serversforhackers.com/c/redirect-http-to-https-nginx
– Haxiel
Nov 21 at 4:27















active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);



);






Dany is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483082%2fnginx-default-configuration-file-issue%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Dany is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















Dany is a new contributor. Be nice, and check out our Code of Conduct.












Dany is a new contributor. Be nice, and check out our Code of Conduct.











Dany is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483082%2fnginx-default-configuration-file-issue%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

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay