2017-07-08 62 views
0

這是我試圖部署一個小的PHP應用程序的第三天。 我們將我們的應用程序,這是3軌應用程序和1個PHP到同一臺服務器。 Rails應用程序工作正常。 PHP不。 我從來沒有真正部署PHP應用程序,所以我通過指南來完成它。到目前爲止,我得到這種情況: 如果我嘗試在瀏覽器中打開PHP應用程序,我會看到默認的Apache頁面。如果我刷新頁面,它會顯示index.php文件的內容,但是會顯示爲空白文本。再次刷新 - 默認的Apache頁面,再次 - index.php的內容。PHP應用程序部署Ubuntu 16.04 nginx Apache設置

我的設置:

的nginx /網站可用/ my.site(啓用了啓用的站點 - )

server { 
    listen 80 default_server; 
    listen [::]:80 default_server; 

root /var/www/my.site/httpdocs; 

# Add index.php to the list if you are using PHP 
index index.php index.html index.htm index.nginx-debian.html; 

server_name my.site www.my.site; 

location/{ 
    proxy_pass http://localhost:8000; 
    include /etc/nginx/proxy_params; 
} 

location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ { 
expires  30d; 
} 

location @proxy { 
    proxy_pass http://127.0.0.1:8000; 
    include /etc/nginx/proxy_params; 
} 
location ~* \.php$ { 
    proxy_pass http://127.0.0.1:8000; 
    include /etc/nginx/proxy_params; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $remote_addr; 
    proxy_set_header Host $host; 
} 
} 

的Apache2 /網站可用/ my.site

ServerName my.site 
ServerAlias www.my.site 

ServerAdmin [email protected] 
DocumentRoot /var/www/my.site/httpdocs 

ErrorLog ${APACHE_LOG_DIR}/error.log 
CustomLog ${APACHE_LOG_DIR}/access.log combined 

的Apache2/ports.conf

NameVirtualHost 127.0.0.1:8000 
Listen 8000 

<IfModule ssl_module> 
    Listen 443 
</IfModule> 

<IfModule mod_gnutls.c> 
    Listen 443 
</IfModule> 

在休息日工作不知道如何解決服務器。任何建議表示讚賞。

+0

我可以知道你爲什麼要使用nginx的作爲代理阿帕奇? – Albert221

+0

@ Albert221我對你沒有適當的答案。我剛剛開始谷歌'的Ubuntu的PHP Apache部署'和那些指南出現了。你能提供更好的解決方案嗎 – alexxero

回答

1

nginx的配置

map $sent_http_content_type $expires { 
    default    off; 
    ~css     max; 
    ~javascript  max; 
    ~image    max; 
    ~font-woff  max; 
    ~video    max; 
    ~zip     max; 
    ~txt     max; 
    } 
expires     $expires; 

server { 
listen 80; 
    server_name exemple.com; 
    root /home/to/exemple.com; 
    index index.php index.html;    

gzip     on; 
gzip_min_length   128; 
gzip_http_version  1.1; 
gzip_buffers   128 32k; 
gzip_types 
    text/css 
    text/javascript 
    text/xml 
    text/plain 
    text/x-component 
    application/javascript 
    application/x-javascript 
    application/json 
    application/xml 
    application/rss+xml 
    application/atom+xml 
    font/truetype 
    font/opentype 
    application/vnd.ms-fontobject 
    image/svg+xml; 
gzip_static on;  
gzip_proxied   expired no-cache no-store private auth; 
gzip_disable   "msie6"; 
gzip_vary    on; 

location/{ 
    proxy_pass http://127.0.0.1:8000; 
    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 X-Forwarded-Proto $scheme; 
    } 
} 

apache配置

PHP 7 MOD

apt install libapache2-mod-php7.0 

PHP5 MOD

apt install libapache2-mod-php 

包括例如php7.0 MOD

a2enmod php7.0 

虛擬主機配置阿帕奇

<VirtualHost *:8000> 
    ServerName exemple.com 
    DocumentRoot /home/to/exemple.com 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
    RewriteEngine On 
<Directory /home/to/exemple.com/> 
    php_admin_flag engine on 
    Options -ExecCGI -Indexes +FollowSymLinks 
    AllowOverride All 
    Require all granted 
</Directory> 
</VirtualHost> 

在apache2.conf 粘貼刪除了NameVirtualHost 127.0.0.1:8000 ServerName 127.0.0.1

systemctl restart apache2 
systemctl restart nginx 

原帖apache2+nginx proxy

+0

謝謝!這有幫助 – alexxero