Nginx-ubuntu Chinese
- Page
- Discuss
- View Source code
- History
Navigation
- Home
- Recent Changes
- Random page
- Page category
- Help
Edit
- Editing guide
- Sand box
- News Update
- word processing
Tools
- Link into page
- Related changes
- Special pages
- Print version
- Fixed link
- Page information
Nginx Directory
- 1 Installing Nginx
- 2 start Nginx
- 3 configuring PHP and MySQL
- 3.1 installing PHP and MySQL
- 3.2 Installation fastcgi
- 3.3 Configuration Nginx
- 4 installing Nginx +uwsgi+ Django
- 5 Configuring Nginx Uwsgi Django
- 6 UWSGI Configuration
- 7 Configuring Django
- 8 No input file specified error
- 9 installing Zend Optimizer
- Ten installed XCache
- Install Eaccelerator
- Shielding Thunderbolt
- Reference
- Learn More
Installing Nginx
sudo apt-get install Nginx
The file structure of Ubuntu after installation is roughly:
- All configuration files are under/etc/nginx, and each virtual host is already under/etc/nginx/sites-available
- Program Files in/usr/sbin/nginx
- The logs were put in/var/log/nginx.
- and has created a startup script Nginx under/etc/init.d/
- The default virtual host directory settings in the/var/www/nginx-default (some versions of the default virtual host directory settings in the/var/www, please refer to the configuration in/etc/nginx/sites-available)
start Nginx
Sudo/etc/init.d/nginx start
Then you can visit, http://localhost/, everything is OK! If you can't access it, don't go ahead and see what the reason is, and then go ahead and fix it. Boot time if the display port 80 is occupied: starting nginx: [Emerg]: Bind () to 0.0.0.0:80 failed (98:address already on use) modify file:/etc/nginx/sites-av Ailable/default, remove the # in front of the Listen, # in the file is the meaning of the comment, and the listen after the 80 port number to their own port, access is to add the port number.
(after installation, if there is a 403 error, it may be the Nginx configuration file site path is incorrect)
configure PHP and MySQLinstall PHP and MySQL
Install PHP and MySQL:
sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
Installing fastcgi
sudo apt-get install PHP5-FPM
Configure Nginx
Modify Nginx configuration file:/etc/nginx/sites-available/default Modify host Name
server_name localhost;
Modify the row of index to:
Index index.php index.html index.htm;
Remove the comments from the following section to support the PHP script:
Location ~ \.php$ {include/etc/nginx/fastcgi_params; #需放在第一行, otherwise there will be an error fastcgi_pass 127.0.0.1:9000;fastcgi_index Index.php;fastcgi_param Script_filename/var/www/nginx-default$fastcgi_script_name;}
Restart Nginx:
/etc/init.d/nginx Stop/etc/init.d/nginx Start
Start fastcgi php:
Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi
In order for php-cgi to boot from: Ubuntu will execute the script in the/etc/rc.local file after booting, so we can add the startup script directly in/etc/rc.local. Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi Add to statement: Exit 0.
Create, Test phpinfo:
sudo vi/var/www/nginx-default/info.php
<?php phpinfo ();?>
Open http://localhost/info.php.
installing Nginx +uwsgi+ Django
This time, the Uwsgi 1.2+django1.4+nginx1.1.19+ubuntu12.04 combination is used to install
First note To install newer software if you are ubuntu11.04 and 11.10 because the kernel is different, the installation software version is different
1. First install the Nginx:sudo apt-get installation Nginx 2. Then: Install the other several before you install the UWSGI: sudo apt-get install mysql-server libxml2 libxml2-dev Python-dev libpcre3 Libpcre3-dev python-mysqldb 3. Installation of Uwsgi: May be due to the software version is not new. 502 error after installing in PPA so install with package:
- wget http://projects.unbit.it/downloads/uwsgi-1.2.tar.gz
- Tar zxvf uwsgi-1.2.tar.gz
- CD uwsgi-1.2
- Make
- CP Uwsgi/usr/bin
Note: If the make process appears as: (Python.h: No file or directory)
4. Install Django before I install it with Ubuntu source. Because of the static issues managed by admin. So I prefer to download the installation instead. Google under Django then go to download https://www.djangoproject.com/download/with chrome download default/home/helios/download then CD then CD download then tar XZVF django-1.4.tar.gz cd Django-1.4 sudo python setup.py install this is the latest version. Copy official website installation method. Then sudo cp django/bin/django-admin.py/usr/bin/next sudo mv/usr/bin/django-admin.py/usr/bin/django-admin This is to be consistent with the operation of the source installation, but do not know if there is a problem. There are no problems. You can come up with a tutorial. OK. The installation is ready.
Establish Project------------------------
1.CD 2.django-admin startproject MySite
|-mysite |--mysite,manage.py |---__init__.py, settings.py, urls.py
Now is the question of the admin static file just said. I'm now going to download the/home/helios/folder inside the Django installer package and copy it to the MySite under the/django-1.4/django/contrib/admin
So keep localhost/admin can appear normal page no longer has no style.
Another solution to the admin static method problem--------
sudo chmod-r 777 folder path. This is the permission to give all sub-files subfolders under the folder.
Then you can install Django from the source sudo apt-get install Python-django and then mkdir/home/helios/mysite/static/admincp-rf/usr/lib/python2.7/ Dist-packages/django/contrib/admin/media/home/helios/mysite/static/adminsudo Chmod-r 777/home/helios/mysite/ Static/admin this is OK.
configuring Nginx Uwsgi Django
Explain the environment:
My Computer user name: Helios;
#sudo Vim/etc/nginx/sites-available/default
The Nginx code appears: (Serial number not copied)
1.
Listen 80;
2.
Root /home/helios/mysite;
3.
server_name youdomain.com# domain name or local localhost;
4.
Location/{ uwsgi_pass 127.0.0.1:9000; Include Uwsgi_params; Access_log off;}
5.
location/static/{ alias/home/helios/mysite/static; AutoIndex on; Allow 127.0.0.1; Deny all; }
6.
location/static/admin/{ alias/home/helios/mysite/static/admin; AutoIndex on; Allow 127.0.0.1; Deny all; }
7.
Location ~ ^.+\. (gif|jpg|png|ico|jpeg) $ { expires 3d;}
8.
Location ~ ^.+\. (CSS|JS) $ { expires 12h;}
And then
#vim/etc/nginx/nginx.conf
1.
User Helios;
2.
Remove the front # of all gzip openings except gzip setting
Now the Nginx configuration is ready.
UWSGI Configuration
#cd/home/helios/mysite #vim wsgi.py
Write on
Import OS import sys from DJANGO.CORE.HANDLERS.WSGI import wsgihandler sys.path.append ("/home/helios/mysite" ) os.environ["django_settings_module"] = "mysite.settings" application = Wsgihandler ()
When it's done
#vim Wsgi.xml
Write on
<uwsgi> <socket>127.0.0.1:9000</socket> <listen>80</listen> < master>true</master> <pidfile>/var/run/nginx.pid</pidfile> <processes>8< /processes> <pythonpath>/home/helios/mysite</pythonpath> <pythonpath>/home/helios /</pythonpath> <module>wsgi</module> <profiler>true</profiler> < memory-report>true</memory-report> <enable-threads>true</enable-threads> < Logdate>true</logdate> #这个是程序占用大小, not too small, too big for the moment do not know #在测试过程中, My Computer under 300 visual inspection. #也可以删除这段, because during the test, if this setting is too small #会出现问题libgcc_s. So.1 must is installed for Pthread_cancel to work #只有在 Ubuntu 12.04 tested, other systems are unclear #为了不容易出错可以删掉, but this tip to needy friends <limit-as>300</limit-as> # Set up your own folder and create an empty file Django.log this flexible <daemonize>/home/helios/mysite/log/django.log</daemonize> </ Uwsgi>
Configure Django
Just configure nginx inside to see these two sections:
location/static/{
Root/home/helios/mysite; Access_log off;
} location/static/admin/{
root/home/helios/mysite/static; Access_log off;
OK now the terminal:
- Cd/home/helios/mysite
- Vim settings.py
See Admin_media_prefix Static_url These two parameters are pointing here, if there's a problem, my parameters are not the two. You can refer to: Media_root = '/home/helios/mysite/static ' Media_u RL = '/static/' admin_media_prefix = '/static/admin/' then database problem: My is MySQL database: terminal
- Cd/home/helios/mysite
- Mysql-h Localhost-u Root-p
Enter password****** >create Database mysite default character set UTF8; (because you want to record Chinese so it defaults to UTF8) >quit
- Vim settings.py
DATABASES = {
' Default ': { ' ENGINE ': ' Django.db.backends.mysql ', # Add ' postgresql_psycopg2 ', ' PostgreSQL ', ' MySQL ', ' sqlite3 ' or ' Oracle '. ' NAME ': ' MySite ', # Or path to database file if using Sqlite3. ' USER ': ' Root ', # not used with sqlite3. ' PASSWORD ': ' ******* ', # not used with sqlite3. ' HOST ': ' localhost ', # Set to empty string for localhost. Not used with sqlite3. ' PORT ': ' 3306 ', # Set to empty string for default. Not used with Sqlite3. }
Finally there are some: language: language_code = ' ZH-CN ' time: time_zone = ' Asia/shanghai '
Other about Django configuration friends can go to the web to search the Django tutorial or official website to see my blog has a similar to the lazy installation of the script is interested can go to see more detailed tutorial http://sishengbang.tk if I have problems with these steps can mail me: [email protected] or [email protected] or my blog www.younguy.tk qq can also add me but to explain nginx+ubuntu+django:845262968 Create a new GitHub project: A Tornado+django+php+nginx+mysql deployment and includes source code Https://github.com/yuyangit/BMProject
no input file specified error
sudo vi/etc/nginx/sites-available/default
Where this field
Location ~ \.php$ {root Html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param script_filename/var/ Www/nginx-default$fastcgi_script_name;include Fastcgi_params;
Attention
Fastcgi_param Script_filename/var/www/nginx-default$fastcgi_script_name;
/var/www/nginx-default change to your Web site root directory, is usually changed to this. The root directory and the Web site root directory are consistent under the server field
Installing Zend Optimizer
PHP version 5.2 is required, do not support Ubuntu10.04 PHP5.3, please refer to PHP5.2. (Zend 5.5 support php5.3,:http://downloads.zend.com/guard/5.5.0/zendguardloader-php-5.3-linux-glibc23-i386.tar.gz)
Download Zend Optimizer. Direct paste, reference version number change (this is 32-bit), otherwise the homepage to register to under
Tar zxvf zendoptimizer-3.3.9-linux-glibc23-i386.tar.gz
Edit PHP.ini
sudo gedit/etc/php5/cgi/php.ini
Start by adding, pay attention to punctuation to English.
[Zend optimizer]zend_optimizer.optimization_level=1 zend_extension= "/usr/local/zend/zendoptimizer.so"
Close php-cgi
sudo killall-hup php-cgi
Restart php-cgi
Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi
No need to restart Nginx
Or the Phpinfo file above, you can see the following information
This program makes use of the Zend Scripting Language engine:zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
Installation XCache
sudo apt-get install Php5-xcache
[Email protected]:/home/qii# dpkg-l | grep xcachii php5-xcache 1.2.2-5 Fast, stable PHP opcode Cacher
The XCache configuration file path is
/etc/php5/conf.d/xcache.ini
Edit PHP.ini
sudo gedit/etc/php5/cgi/php.ini
Add the contents of Xcache.ini to php.ini.
Close php-cgi
sudo killall-hup php-cgi
Restart php-cgi
Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi
No need to restart Nginx to check if installation is successful
[Email protected]:/home/qii# php-vphp 5.2.10-2ubuntu6 with Suhosin-patch 0.9.7 (CLI) (built:oct 16:30:10) Copyri Ght (c) 1997-2009 the PHP groupzend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with XCache v1.2.2, Copyr Ight (c) 2005-2007, by MOo
There should be a XCache module on the front info.php page.
XCache Module for info page |
A bit strange here is that if you do not add the contents of the Xcache.ini Php.ini,apache can also be loaded into XCache, but info.php on the XCache module.
Installing Eaccelerator
sudo apt-get install Php5-dev
Download Eaccelerator
wget http://sourceforge.net/projects/eaccelerator/files/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2
Tar jxvf eaccelerator-0.9.6.1.tar.bz2
Phpizesudo./configure-enable-eaccelerator=sharedsudo make
[Email protected]:~/tmp/eaccelerator-0.9.6.1$ sudo make installinstalling shared extensions: /usr/lib/php5/ 20090626+lfs/
Modify the php.ini file, install it as a zend extension, preferably at the beginning, before [Zend], and avoid the puzzling problem:
sudo vi/etc/php5/cgi/php.ini
[eaccelerator]zend_extension= "/usr/lib/php5/20090626+lfs/eaccelerator.so" eaccelerator.shm_size= "16" Eaccelerator.cache_dir= "/tmp/eaccelerator" eaccelerator.enable= "1" eaccelerator.optimizer= "1" eaccelerator.check_ Mtime= "1" eaccelerator.debug= "0" eaccelerator.filter= "" eaccelerator.shm_max= "0" eaccelerator.shm_ttl= "0" eaccelerator.shm_prune_period= "0" eaccelerator.shm_only= "0" eaccelerator.compress= "1" eaccelerator.compress_level = "9" eaccelerator.allowed_admin_path= "/var/www/nginx-default/control.php"
Create a cache directory
Eaccelerator.cache_dir= "/var/cache/eaccelerator" here defines the cache path
The default value is/tmp/eaccelerator, which is very simple because anyone can write to the directory, but it is not advisable, because the system automatically cleans up the directory after a reboot. A better place is the/var/cache/eaccelerator. Create the directory and make sure that it is writable to the consumer of eaccelerator (usually the user is your network server runner, possibly Www-data). Continue with the default values:
Mkdir/tmp/eaccelerator
chmod 777/tmp/eaccelerator
Change to/var/cache/eaccelerator words so continue, first change php.ini
sudo mkdir/var/cache/eacceleratorsudo chown root:www-data/var/cache/eacceleratorsudo chmod u=rwx,g=rwx,o=/var/cache /eaccelerator
Copy the control file control.php to the Web site root directory
sudo cp control.php/var/www/nginx-default/
Modify control.php $user and $PW, default is admin and Eaccelerator
Close php-cgi
sudo killall-hup php-cgi
Restart php-cgi
Spawn-fcgi-a 127.0.0.1-p 9000-c 10-u www-data-f/usr/bin/php-cgi
No need to restart Nginx to open http://localhost/control.php
Eaccelerator control.php Page |
To view the previous Info.php page, the following fields are available:
This program makes use of the Zend Scripting Language engine:zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies With eaccelerator v0.9.6.1, Copyright (c) 2004-2010 eaccelerator, by Eaccelerator
Shielding Thunderbolt
New
/etc/nginx/agent.conf
if ($http _user_agent ~ "mozilla/4.0\ \ (compatible;\ Msie\ 6.0;\ Windows\ nt\ 5.1;\ Sv1;\. Net\ clr\ 1.1.4322;\. Net\ clr\ 2.0.50727\) {return 404;}
Note that spaces and brackets need to be escaped with "\".
Then in the site configuration
include/etc/nginx/agent.conf;
Thunderbolt Usera-gent and this practice failure situation see apache# shielded Thunderbolt
Reference
Nginx prohibits a user_agent method
Learn More
- Nginx wiki: Http://wiki.codemongers.com/NginxChs
- Nginx's Chinese station: http://www.nginx.cn
Classification:
Nginx + spawn-fcgi-ubuntu Chinese