我开始尝试nginx了。首先,我想安装phpmyadmin,我认为这是一个很好的练习。
**资料
*组合:
公用html文件夹:
root@server01:/usr/share/nginx/html# ls -l
total 12
-rw-r--r-- 1 root root 537 Mar 4 2014 50x.html
-rw-r--r-- 1 root root 612 Mar 4 2014 index.html
-rw-r--r-- 1 root root 20 Jan 1 13:21 info.php
lrwxrwxrwx 1 root root 21 Dec 31 18:41 phpmyadmin -> /usr/share/phpmyadmin配置到可获得的站点:
root@server01:/etc/nginx/sites-available# ls -l
total 8
-rw-r--r-- 1 root root 833 Jan 1 14:19 phpmyadmin.soapoperator.com
-rw-r--r-- 1 root root 2603 Jan 1 13:35 default主机的配置
server {
listen 80;
#listen [::]:80 ipv6only=on;
server_name phpmyadmin.soapoperator.com;
root /usr/share/nginx/html/phpmyadmin;
index index.php index.html index.htm;
# allow
#allow 82.230.xx.x;
#allow 2a01:e35:2e65:3070:xxx:xxx:c95c:69a;
# drop rest of the world
#deny all;
# Logs
access_log /var/log/phpmyadmin.access_log;
error_log /var/log/phpmyadmin.error_log;
# Default location settings
location / {
charset utf-8;
client_max_body_size 20M;
}
location ~* \.php$ {
# Prevent Zero-day exploit
try_files $uri =404;
# Pass the PHP scripts to FastCGI server
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_param HTTPS off;
}
}我启用了这个网站:
root@server01:/etc/nginx/sites-enabled# ls -l
total 0
lrwxrwxrwx 1 root root 46 Jan 1 13:54 phpmyadmin.soapoperator.com -> /etc/nginx/sites-available/phpmyadmin.soapoperator.com
lrwxrwxrwx 1 root root 34 Dec 31 14:28 default -> /etc/nginx/sites-available/default不幸的是,当我访问phpmyadmin url时,我到达了nginx欢迎页面。所以我想vhost配置得不太好。但是为什么呢?
我想知道这是否是由于ipv6配置造成的问题。我试图添加到主机配置中:
listen [::]:80 ipv6only=on;但我发现了一个错误:
2016/01/02 11:48:45 [emerg] 12636#0: duplicate listen options for [::]:80 in /etc/nginx/sites-enabled/default:22或者是php问题,因为当我试图访问ip]/info.php时,该文件是作为下载而不是额外的。
提前感谢您的帮助。jb
[编辑]
nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
##
# Special for 502 error
##
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
##
# Access control
##
include blockips.conf;
}发布于 2016-01-08 22:40:44
最后,我解决了编辑/etc/php5/fpm/php.ini的问题,并确保将cgi.fix_pathinfo设置为0。另一方面,我将侦听= /var/run/php5-fpm.sock放在/etc/php5 5/fpm/info.gov.hk.d/www.conf中。
我不知道哪一项修改能真正解决这个问题。
我的研究:http://www.sitepoint.com/setting-up-php-behind-nginx-with-fastcgi/,Nginx serves .php files as downloads, instead of executing them
最后,我的vhost是这样工作的:
server {
listen 80;
listen [::]:80;
server_name phpmyadmin.soapoperator.com;
server_name_in_redirect off;
root /usr/share/nginx/html/phpmyadmin;
index index.php index.html index.htm;
# allow
allow 82.230.xx.x;
allow 2a01:e35:xxxx:xxxx::/xx;
# drop rest of the world
deny all;
# Logs
access_log /var/log/phpmyadmin.access_log;
error_log /var/log/phpmyadmin.error_log;
# Default location settings
location / {
try_files $uri $uri/ /index.php?$args;
charset utf-8;
client_max_body_size 20M;
}
# Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 360d;
}
# Deny access to .htaccess files, if Apache's document root
location ~ /\.ht {
deny all;
}
location ~ /(libraries|setup/frames|setup/libs) {
deny all;
return 404;
}
# Pass the PHP scripts to FastCGI server
location ~* \.php$ {
# Prevent Zero-day exploit
try_files $uri =404;
#
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_param HTTPS off;
}
# Redirect server error pages to the static page
error_page 403 /403.html;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
# Exclude favicon from the logs to avoid bloating when it's not available
location /favicon.ico {
log_not_found off;
access_log off;
}
}https://stackoverflow.com/questions/34569925
复制相似问题