在 CentOS 6.6 机器上,我将 nginx 设置为服务两个虚拟主机。一个用于 SSL,一个用于基本 HTTP。
/etc/nginx/default.conf:
server {
listen 80 default_server;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
我的 /etc/nginx/conf.d/virtual.conf 用于 HTTP:
server {
listen example.com:80;
server_name example.com alias www.example.com;
location / {
root /var/www/example.com/htdocs/;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /var/www/example.com/htdocs/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我的/etc/nginx/conf.d/ssl.conf:
server {
listen 443;
server_name example.com;
ssl on;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
location / {
root /var/www/example.com/htocs/;
index index.html index.htm;
}
location ~ \.php$ {
root /var/www/example.com/htdocs/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我的 htdocs 文件夹的内容:
[root@mydomain htdocs]# ls -lha
total 192K
drwxr-xr-x 5 myuser myuser 4.0K Mar 3 19:57 .
drwxr-xr-x 4 myuser myuser 4.0K Mar 3 18:52 ..
-rw-r--r-- 1 root root 418 Mar 3 19:54 index.php
-rw-r--r-- 1 root root 20 Mar 3 19:36 info.php
-rw-r--r-- 1 root root 20K Mar 3 19:54 license.txt
-rw-r--r-- 1 root root 7.1K Mar 3 19:54 readme.html
-rw-r--r-- 1 root root 4.9K Mar 3 19:54 wp-activate.php
drwxr-xr-x 9 root root 4.0K Mar 3 19:54 wp-admin
-rw-r--r-- 1 root root 271 Mar 3 19:54 wp-blog-header.php
-rw-r--r-- 1 root root 4.9K Mar 3 19:54 wp-comments-post.php
-rw-r--r-- 1 root root 2.7K Mar 3 19:54 wp-config.php
-rw-r--r-- 1 root root 2.7K Mar 3 19:54 wp-config-sample.php
drwxr-xr-x 4 root root 4.0K Mar 3 19:54 wp-content
-rw-r--r-- 1 root root 2.9K Mar 3 19:54 wp-cron.php
drwxr-xr-x 12 root root 4.0K Mar 3 19:54 wp-includes
-rw-r--r-- 1 root root 2.4K Mar 3 19:54 wp-links-opml.php
-rw-r--r-- 1 root root 2.7K Mar 3 19:54 wp-load.php
-rw-r--r-- 1 root root 33K Mar 3 19:54 wp-login.php
-rw-r--r-- 1 root root 8.1K Mar 3 19:54 wp-mail.php
-rw-r--r-- 1 root root 11K Mar 3 19:54 wp-settings.php
-rw-r--r-- 1 root root 25K Mar 3 19:54 wp-signup.php
-rw-r--r-- 1 root root 4.0K Mar 3 19:54 wp-trackback.php
-rw-r--r-- 1 root root 3.0K Mar 3 19:54 xmlrpc.php
令我感到困惑的是,我可以直接访问https://example.com/info.php它提供典型的 php 配置内容。但是尝试访问其他任何内容都会引发 404。
有什么建议吗?
答案1
修正拼写错误root /var/www/example.com/htocs/;