I'm trying get a website with one subdomain (for the time-being) set up in nginx on a Centos7 server with ssl encryption provided by Let's Encrypt's certbot.
I have nginx successfully installed, I have set up my domains: example.com
www.example.com
and ci.example.com
and gotten the certs issued without any problems (my browser says 'secured' and it auto redirects to https from http requests.)
Now I want to have ci.example.com
to proxy through to the localhost:6500 port ( proxy_pass
I believe it's called). I've tried following: this blog post from 2014 but nginx keeps serving the standard "Welcome to Nginx page".
All the other articles/tutorials are for an older version of nginx (that doesn't use /etc/nginx/nginx.conf.
Here is the /etc/nginx/nginx.conf
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
server_name example.com www.example.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/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
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = ci.example.com) {
return 301 https://$host$request_uri;
} #added by me
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 404; # managed by Certbot
I've figured it out and saving this for posterity.
I didn't set up nginx correctly before I ran the certbot --nginx command.
Here's what you are supposed to do:
From a clean install of Centos 7
ensure Centos is up to date through sudo yum update -y
then install nginx through: sudo yum install nginx -y
it comes default but this ensures it is up to date.
then follow this guide to get unsecured http://ci.yoursite.com
and http://www.yoursite.com
working as you want them.
Note - if you have issues with being unable to start nginx due to: [emerg] open() "/usr/share/nginx/logs/ci.yoursite.access.log" failed (13: Permission denied)
Use: su -c "setenforce 0"
It will set SELinux to permissive mode and allow nginx to start.
then follow: This guide to get Let's Encrypt and Certbot --nginx working.
your final /etc/nginx/conf.d/ci.yourserver.conf
should look like this to reroute to port 6500 in this example:
server {
server_name ci.example.com;
access_log logs/ci.example.access.log main;
root /var/www/ci.example.com/html;
index index.html index.htm;
location / {
proxy_pass http://localhost:6500;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
proxy_buffers 4 32k;
client_max_body_size 8m;
client_body_buffer_size 128k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/ci.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ci.example.com/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
}
server {
if ($host = ci.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name ci.example.com;
return 404; # managed by Certbot
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.