Nginx的反代与PHP项目代码
proxy-web-ssl.conf
############################server开始####################
server {
######################访问域名及监听端口配置#############
listen 80 ;
listen [::]:80;
listen 443 ssl http2 ;
listen [::]:443 ssl http2;
server_name demo.com;
######################访问域名及监听端口配置结束#########
index index.php index.html index.htm default.php default.htm default.html;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 90000m;
sendfile on;
tcp_nopush on;
#################acme证书自动续签验证####################
#location ^~ /.well-known/acme-challenge {
# allow all;
# root /usr/share/nginx/html;
#}
################acme证书自动续签验证结束##################
##################允许在HTTP头中使用下划线################
underscores_in_headers on;
######################################################
location ^~ / {
##################反代IP和端口##########################
proxy_pass http://127.0.0.1:port;
##################反代IP和端口结束######################
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_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
add_header X-Cache $upstream_cache_status;
add_header Strict-Transport-Security "max-age=31536000";
}
######################80端口重定向到443端口#############
if ($scheme = http) {
return 301 https://$host$request_uri;
}
#######################80端口重定向到443端口结束#########
#####################ssl证书配置#######################
ssl_certificate /ssl/demo.com/cert.crt;
ssl_certificate_key /ssl/demo.com/private.key;
ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
proxy_set_header X-Forwarded-Proto https;
add_header Strict-Transport-Security "max-age=31536000";
########################证书配置结束#####################
}
###########################server结束#######################
php-web.conf
############################server开始####################
server {
sudo service nginx restart
listen 80 ;
listen [::]:80;
listen 443 ssl http2 ;
listen [::]:443 ssl http2;
server_name demo.com;
######################访问域名及监听端口配置结束#########
######################网页根地址#########
root /www/demo.com;
######################网页根地址结束#########
index index.php index.html index.htm default.php default.htm default.html;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 90000m;
sendfile on;
tcp_nopush on;
#################acme证书自动续签验证####################
#location ^~ /.well-known/acme-challenge {
# allow all;
# root /usr/share/nginx/html;
#}
################acme证书自动续签验证结束##################
##################允许在HTTP头中使用下划线################
underscores_in_headers on;
######################################################
######################80端口重定向到443端口#############
if ($scheme = http) {
return 301 https://$host$request_uri;
}
#######################80端口重定向到443端口结束#########
######################支持PHP页面#########
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php{version}-fpm.sock;
}
######################支持PHP页面结束#########
#####################ssl证书配置#######################
ssl_certificate /ssl/demo.com/cert.crt;
ssl_certificate_key /ssl/demo.com/private.key;
ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
proxy_set_header X-Forwarded-Proto https;
add_header Strict-Transport-Security "max-age=31536000";
########################证书配置结束#####################
}
###########################server结束#######################