Nginx default configuration file issue
up vote
1
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 reason for using NGINX is to send HTTP and HTTPS requests to Varnish and then Varnish will send it to the Apache server.
Below is my default NGINX configuration 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:
- It does not direct HTTP requests to HTTPS
- it does not direct non-www to www
So, is the following command right:
proxy_pass http://127.0.0.1:81;
to direct requests from NGINX to Varnish or should 127.0.0.1
be the actual server address?
Please, can you give me the right configuration for the default NGINX file?
proxy redirection nginx
add a comment |
up vote
1
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 reason for using NGINX is to send HTTP and HTTPS requests to Varnish and then Varnish will send it to the Apache server.
Below is my default NGINX configuration 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:
- It does not direct HTTP requests to HTTPS
- it does not direct non-www to www
So, is the following command right:
proxy_pass http://127.0.0.1:81;
to direct requests from NGINX to Varnish or should 127.0.0.1
be the actual server address?
Please, can you give me the right configuration for the default NGINX file?
proxy redirection nginx
add a comment |
up vote
1
down vote
favorite
up vote
1
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 reason for using NGINX is to send HTTP and HTTPS requests to Varnish and then Varnish will send it to the Apache server.
Below is my default NGINX configuration 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:
- It does not direct HTTP requests to HTTPS
- it does not direct non-www to www
So, is the following command right:
proxy_pass http://127.0.0.1:81;
to direct requests from NGINX to Varnish or should 127.0.0.1
be the actual server address?
Please, can you give me the right configuration for the default NGINX file?
proxy redirection nginx
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 reason for using NGINX is to send HTTP and HTTPS requests to Varnish and then Varnish will send it to the Apache server.
Below is my default NGINX configuration 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:
- It does not direct HTTP requests to HTTPS
- it does not direct non-www to www
So, is the following command right:
proxy_pass http://127.0.0.1:81;
to direct requests from NGINX to Varnish or should 127.0.0.1
be the actual server address?
Please, can you give me the right configuration for the default NGINX file?
proxy redirection nginx
proxy redirection nginx
edited Nov 20 at 23:16
Blackwood
2,68161727
2,68161727
asked Nov 20 at 21:24
Dany
61
61
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Super User!
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1377107%2fnginx-default-configuration-file-issue%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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