我已经安装了带有 php-fpm 的 nginx。当我尝试访问 example.org 时,它会将我重定向到https://example.com 我的配置有什么问题?
nginx.conf
user www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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;
error_log /var/log/nginx/error.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
include vhosts/*.conf;
}
例如.com.conf
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri; # enforce https
}
server {
listen 443 ssl;
server_name example.com;
root /usr/local/www/example.com;
index index.php;
charset utf-8;
## Logging
access_log /var/log/nginx/example.com-access.log;
error_log /var/log/nginx/example.com-error.log;
## SSL settings
ssl_certificate /usr/local/etc/nginx/ssl/example.com.pem;
ssl_certificate_key /usr/local/etc/nginx/ssl/example.com.pem;
ssl_protocols TLSv1.2;
ssl_ciphers "EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4";
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_ecdh_curve secp521r1;
add_header Strict-Transport-Security max-age=31536000;
location / {
try_files $uri/ index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
}
例子.org.conf
server {
listen 80;
server_name example.org;
return 301 https://example.org$request_uri;
}
server {
listen 443;
server_name example.org;
root /usr/local/www/example.org;
# logs
access_log /var/log/nginx/example.org_access.log;
error_log /var/log/nginx/example.org_error.log;
## SSL settings
ssl_certificate /usr/local/etc/nginx/ssl/example.com.pem;
ssl_certificate_key /usr/local/etc/nginx/ssl/example.com.pem;
ssl_protocols TLSv1.2;
ssl_ciphers "EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4";
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_ecdh_curve secp521r1;
add_header Strict-Transport-Security max-age=31536000;
# Default location setting
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
# Pass the PHP scripts to FastCGI server
location ~ \.php$ {
# Prevent Zero-day exploit
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Deny access to .htaccess if Apache's doc. root
location ~ /\.ht {
deny all;
}
# Exclude favicon from logs
location /favicon.ico {
log_not_found off;
access_log off;
}
}