2017-08-16 877 views
0

服务器配置: Centos的7 + PHP7 + PHP-FPM + MariaDB的10 + Nginx的作为为Apache +的VirtualminNginx的欢迎测试页面,而不是主页

反向代理我是新来设置服务器。我不确定我在哪里搞砸了,并且我尝试过在数字海洋和其他许多论坛上根据建议在线搜索和编辑,但仍然没有成功。更改完成后,我总是重新启动nginx,httpd和php-fpm。

我有2个虚拟服务器,他们都打开Nginx的测试页面,而不是他们各自的主页。

我一直在尝试配置,但没有成功。请帮忙。

以下是我的虚拟服务器的配置文件。

1)等/ nginx的/ conf.d/default.conf

server { 
    listen 80; 

    root /home/~; 
    index index.php index.html index.htm; 

    server_name localhost; 

    location/{ 
    try_files $uri $uri/ /index.php; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $remote_addr; 
    proxy_set_header Host $host; 
    proxy_pass http://127.0.0.1:8080; 
    } 

    location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    try_files $uri $uri/ =404; 
    #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
fastcgi_pass 127.0.0.1:9000; 
    #fastcgi_pass php-fpm; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params; 

    } 

    location ~ /\.ht { 
      deny all; 
    } 

}

2)等/ nginx的/ conf.d/PHP-fpm.conf

# PHP-FPM FastCGI server 
# network or unix domain socket configuration 

upstream php-fpm { 
    server 127.0.0.1:9000; 
    #server unix:/run/php-fpm/www.sock; 

} 

3)etc/nginx/nginx.conf

user nginx; 
worker_processes auto; 

worker_rlimit_nofile 10000; 

# only log critical errors 
error_log /var/log/nginx/error.log crit; 
pid /run/nginx.pid; 

include /usr/share/nginx/modules/*.conf; 

events { 
worker_connections 1024; 
use epoll; 
multi_accept on; 
} 

http { 
include mime.types; 
fastcgi_buffers 8 16k; 
fastcgi_buffer_size 32k; 
fastcgi_connect_timeout 300; 
fastcgi_send_timeout 300; 
fastcgi_read_timeout 300; 
default_type application/octet-stream; 

log_format main  '$remote_addr - $remote_user [$time_local] ' 
    '"$request" $status $bytes_sent ' 
    '"$http_referer" "$http_user_agent" ' 
    '"$gzip_ratio"'; 

log_format download '$remote_addr - $remote_user [$time_local] ' 
    '"$request" $status $bytes_sent ' 
    '"$http_referer" "$http_user_agent" ' 
    '"$http_range" "$sent_http_content_range"'; 

access_log /var/log/nginx/access.log main; 
error_log /var/log/nginx/error.log; 

# cache informations about FDs, frequently accessed files 
# can boost performance, but you need to test those values 
open_file_cache max=200000 inactive=20s; 
open_file_cache_valid 2m; 
open_file_cache_min_uses 5; 
open_file_cache_errors on; 

# to boost I/O on HDD we can disable access logs 
access_log off; 
# copies data between one FD and other from within the kernel 
# faster then read() + write() 
sendfile on;  
# send headers in one peace, its better then sending them one by one 
tcp_nopush on; 
# don't buffer data sent, good for small data bursts in real time 
tcp_nodelay on; 

    types_hash_max_size 2048; 
index index.php index.html index.htm; 

    include /etc/nginx/conf.d/*.conf; 
index index.php index.html index.htm; 
server_names_hash_bucket_size 128; 
## 
# Gzip Settings 
## 
# reduce the data that needs to be sent over network -- for testing environment 
gzip on; 
    gzip_http_version 1.1; 
gzip_min_length 10240; 
gzip_proxied expired no-cache no-store private auth; 
gzip_vary on; 
gzip_comp_level 6; 
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js; 
gzip_buffers 16 8k; 
gzip_disable "MSIE [1-6]\.(?!.*SV1)"; 

# allow the server to close connection on non responding client, this will free up memory 
reset_timedout_connection on; 
# request timed out -- default 60 
client_body_timeout 3m; 
# if client stop responding, free up memory -- default 60 
send_timeout 3m; 
# server will close connection after this time -- default 75 
keepalive_timeout 65; 
# number of requests client can make over keep-alive -- for testing environment 
keepalive_requests 100000; 

ignore_invalid_headers on; 
client_max_body_size 100m; 
connection_pool_size 256; 
request_pool_size 4k; 
output_buffers 4 32k; 
postpone_output 1460; 

# limit the number of connections per single IP 
limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m; 
# limit the number of requests for a given session 
limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=5r/s; 
# if the request body size is more than the buffer size, then the entire (or partial) 
# request body is written into a temporary file 
client_body_buffer_size 128k; 
# headerbuffer size for the request header from client -- for testing environment 
client_header_buffer_size 3m; 
# maximum number and size of buffers for large headers to read from client request 
large_client_header_buffers 4 256k; 
# how long to wait for the client to send a request header -- for testing environment 
client_header_timeout 3m; 
    server_tokens off; 

#nginx compression 
log_format compression '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" "$gzip_ratio"'; 

# Upstream to abstract backend connection(s) for PHP. 
upstream php { 
      #this should match value of "listen" directive in php-fpm pool 
    #server unix:/tmp/php-fpm.sock; 
    server 127.0.0.1:9000; 
} 
server { 
    listen 80; 
# listen  [::]:80 default_server; 
    server_name _; 
    #root   /home/~; 
    root   /usr/share/nginx/html; 

    # Load configuration files for the default server block. 
    include /etc/nginx/default.d/*.conf; 

    error_page 404 /404.html; 
     location = /40x.html { 
    } 

    error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
    } 
    # zone which we want to limit by upper values, we want limit whole server 
    limit_conn conn_limit_per_ip 10; 
    limit_req zone=req_limit_per_ip burst=10 nodelay; 

    location ~* .(woff|eot|ttf|svg|mp4|webm|jpg|jpeg|png|gif|ico|css|js)$ { 
    expires max; 
    } 
    gzip on; 
    access_log /var/log/nginx/access.log compression; 
} 

#1st virtual server 

server { 
    listen 80; 
    server_name website1.co www.website1.co; 
    root /home/website1/public_html; 
    index index.html index.htm index.php; 
    access_log /var/log/virtualmin/website1_access_log; 
    error_log /var/log/virtualmin/website1_error_log; 

    # nginx configuration 

    location/{ 
    #for web application 
    if (!-e $request_filename){ 
    rewrite ^(/)?api/.*$ /api/index.php; 
    } 
    if (!-e $request_filename){ 
    rewrite ^(/)?customer/.*$ /customer/index.php; 
    } 
    if (!-e $request_filename){ 
    rewrite ^(/)?backend/.*$ /backend/index.php; 
    } 
    if (!-e $request_filename){ 
    rewrite ^(.*)$ /index.php; 
    } 
    index index.html index.htm index.php; 
    #web application end 

    # [pre-existing configurations, if applicable] 
    autoindex on; 
    autoindex_exact_size off; 

    client_max_body_size 10m; 
    client_body_buffer_size 128k; 

    proxy_send_timeout 90; 
    proxy_read_timeout 90; 
    proxy_buffer_size 128k; 
    proxy_buffers  4 256k; 
    proxy_busy_buffers_size 256k; 
    proxy_temp_file_write_size 256k; 
    proxy_connect_timeout 30s; 

    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $remote_addr; 
    proxy_set_header Host $host; 

    proxy_pass http://127.0.0.1:8080; 
} 

#error_page 404    /404.html; 
# redirect server error pages to the static page /50x.html 
# 
error_page 500 502 503 504 /50x.html; 

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
# 
location ~ \.php$ { 
    try_files $uri $uri/ /index.php?$args; 
    fastcgi_index index.php; 
    fastcgi_pass 127.0.0.1:9000; 
    #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
    fastcgi_split_path_info ^(.+\.php)(.*)$; 
    fastcgi_param PATH_INFO  $fastcgi_path_info; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param SCRIPT_NAME  $fastcgi_script_name; 

    fastcgi_read_timeout 600s; 
    fastcgi_send_timeout 600s; 
    include fastcgi_params; 
} 

# deny access to .htaccess files, if Apache's document root 
# concurs with nginx's one 
# 
location ~ /\.ht { 
    access_log off; 
    log_not_found off; 
    deny all; 
} 
    listen 443 ssl; 
    ssl_certificate /home/website1/ssl.cert; 
    ssl_certificate_key /home/website1/ssl.key; 
} 

#2nd virtual server 

server { 
    server_name website2.co www.website2.co; 
    listen 80; 
    root /home/website2/public_html; 
    index index.html index.htm index.php; 
    access_log /var/log/virtualmin/website2_access_log; 
    error_log /var/log/virtualmin/website2_error_log; 
    fastcgi_param GATEWAY_INTERFACE CGI/1.1; 
    fastcgi_param SERVER_SOFTWARE nginx; 
    fastcgi_param QUERY_STRING $query_string; 
    fastcgi_param REQUEST_METHOD $request_method; 
    fastcgi_param CONTENT_TYPE $content_type; 
    fastcgi_param CONTENT_LENGTH $content_length; 
    fastcgi_param SCRIPT_FILENAME /home/website2/public_html$fastcgi_script_name; 
    fastcgi_param SCRIPT_NAME $fastcgi_script_name; 
    fastcgi_param REQUEST_URI $request_uri; 
    fastcgi_param DOCUMENT_URI $document_uri; 
    fastcgi_param DOCUMENT_ROOT /home/website2/public_html; 
    fastcgi_param SERVER_PROTOCOL $server_protocol; 
    fastcgi_param REMOTE_ADDR $remote_addr; 
    fastcgi_param REMOTE_PORT $remote_port; 
    fastcgi_param SERVER_ADDR $server_addr; 
    fastcgi_param SERVER_PORT $server_port; 
    fastcgi_param SERVER_NAME $server_name; 
    fastcgi_param HTTPS $https; 
    location ~ \.php$ { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       try_files $uri $uri/ =404; 
     fastcgi_pass 127.0.0.1:9000; 
        include fastcgi.conf; 

    } 

    location/{ 
    client_max_body_size 10m; 
    client_body_buffer_size 128k; 

    proxy_send_timeout 90; 
    proxy_read_timeout 90; 
    proxy_buffer_size 128k; 
    proxy_buffers  4 256k; 
    proxy_busy_buffers_size 256k; 
    proxy_temp_file_write_size 256k; 
    proxy_connect_timeout 30s; 

    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $remote_addr; 
proxy_set_header Host $host; 

    proxy_pass http://127.0.0.1:8080; 
    } 
    listen 443 ssl; 
    ssl_certificate /home/website2/ssl.cert; 
    ssl_certificate_key /home/website2/ssl.key; 
} 

任何帮助woul d非常有帮助。 在此先感谢。

+0

您在哪里放置第一个和第二个虚拟conf文件?什么名字和地点? –

+0

都在相同的etc/nginx/nginx.conf文件中。在http {}内部,紧跟在具有server_name _的服务器{}之后; – dswong

回答

0

从nginx.conf

server { 
    listen 80; 

# listen  [::]:80 default_server; 

server_name _; 
#root   /home/~; 
root   /usr/share/nginx/html; 

# Load configuration files for the default server block. 
include /etc/nginx/default.d/*.conf; 

error_page 404 /404.html; 
    location = /40x.html { 
} 

error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
} 
# zone which we want to limit by upper values, we want limit whole server 
limit_conn conn_limit_per_ip 10; 
limit_req zone=req_limit_per_ip burst=10 nodelay; 

location ~* .(woff|eot|ttf|svg|mp4|webm|jpg|jpeg|png|gif|ico|css|js)$ { 
expires max; 
} 
gzip on; 
access_log /var/log/nginx/access.log compression; 

}

server_name _;指任何虚拟主机,因此它是在你的配置回应的第一件事就是取下一节。虚拟主机的其余都没有征求仅

编辑 - 在你的configs年08月17

你有一大堆乱七八糟的,包括来自不同目录包括。我建议你删除nginx并重新安装并重新修改基本配置。你也在你的设置中使用httpd

proxy_pass http://127.0.0.1:8080;意味着任何不是php的代码都会代理到您的httpd服务器,并且您的root实际上并未被使用。

你的try_files $uri $uri/ =404;不应该在location ~ \.php$ {块内,而应该在location \ {块内。您的location \ {区块中也不应该有proxy_pass

+0

删除了它,但两个网站仍显示“欢迎使用Fedora上的nginx!”测试页面。我已经添加了一个info.php文件,我可以访问它在website1.co/info.php没有问题。 – dswong

+0

尝试删除default.conf,看看它是否有效 –

+0

尝试过,仍然显示“Welcome to nginx on Fedora!”测试页面。 我尝试过使用新的浏览器并删除了缓存,但问题仍然存在。 – dswong